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 {
const url = req.originalUrl.startsWith('/')
? req.originalUrl.slice(1)
: req.originalUrl;
const siteCache = await this.aragami.get(SiteCache, url);
if (siteCache) {
this.log(`Cache hit for ${url}`);
return siteCache.html;
}
this.log(`Rendering ${url}`);
try {
const html = await this.puppeteerService.render(url);
await this.aragami.set(SiteCache, { url, html });
return html;
} catch (e) {
this.error(`Error rendering ${url}`, e);
throw new BlankReturnMessageDto(
404,
`Page not found: ${url}`,
).toException();
}
return this.aragami.lock(url, async () => {
const siteCache = await this.aragami.get(SiteCache, url);
if (siteCache) {
this.log(`Cache hit for ${url}`);
return siteCache.html;
}
this.log(`Rendering ${url}`);
try {
const html = await this.puppeteerService.render(url);
await this.aragami.set(SiteCache, { url, html });
return html;
} catch (e) {
this.error(`Error rendering ${url}`, e);
throw new BlankReturnMessageDto(
404,
`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