Commit 7b26e1fb authored by nanahira's avatar nanahira

use lock

parent d6b25514
Pipeline #20030 passed with stages
in 1 minute and 15 seconds
...@@ -27,22 +27,24 @@ export class AppService extends ConsoleLogger { ...@@ -27,22 +27,24 @@ export class AppService extends ConsoleLogger {
const url = req.originalUrl.startsWith('/') const url = req.originalUrl.startsWith('/')
? req.originalUrl.slice(1) ? req.originalUrl.slice(1)
: req.originalUrl; : req.originalUrl;
const siteCache = await this.aragami.get(SiteCache, url); return this.aragami.lock(url, async () => {
if (siteCache) { const siteCache = await this.aragami.get(SiteCache, url);
this.log(`Cache hit for ${url}`); if (siteCache) {
return siteCache.html; this.log(`Cache hit for ${url}`);
} return siteCache.html;
this.log(`Rendering ${url}`); }
try { this.log(`Rendering ${url}`);
const html = await this.puppeteerService.render(url); try {
await this.aragami.set(SiteCache, { url, html }); const html = await this.puppeteerService.render(url);
return html; await this.aragami.set(SiteCache, { url, html });
} catch (e) { return html;
this.error(`Error rendering ${url}`, e); } catch (e) {
throw new BlankReturnMessageDto( this.error(`Error rendering ${url}`, e);
404, throw new BlankReturnMessageDto(
`Page not found: ${url}`, 404,
).toException(); `Page not found: ${url}`,
} ).toException();
}
});
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment