refactor: reduce one redis flight
This commit is contained in:
parent
d89e24f796
commit
f3e545057d
1 changed files with 5 additions and 4 deletions
|
@ -148,12 +148,13 @@ class SetCache {
|
||||||
protected async fetch() {
|
protected async fetch() {
|
||||||
// Sync from DB if nothing is cached yet or cache is expired
|
// Sync from DB if nothing is cached yet or cache is expired
|
||||||
const ttlKey = `${this.key}:fetched`;
|
const ttlKey = `${this.key}:fetched`;
|
||||||
const fetched = await redisClient.exists(ttlKey);
|
if (
|
||||||
|
!(await this.hasFollowing()) ||
|
||||||
if (!(await this.hasFollowing()) || fetched === 0) {
|
(await redisClient.exists(ttlKey)) === 0
|
||||||
|
) {
|
||||||
await redisClient.del(this.key);
|
await redisClient.del(this.key);
|
||||||
await this.follow(...(await this.fetcher()));
|
await this.follow(...(await this.fetcher()));
|
||||||
await redisClient.set(ttlKey, "yes", "EX", 60 * 30);
|
await redisClient.set(ttlKey, "yes", "EX", 60 * 30); // Expires in 30 minutes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue