Skip to content

Commit a767ffd

Browse files
committed
increase viewer count cache size and persistence interval
1 parent c028c17 commit a767ffd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

modules/memo/src/main/ViewerCount.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ final class ViewerCountApi(db: lila.db.Db, cacheApi: CacheApi)(using scheduler:
4343

4444
import ViewerCount.*
4545

46+
private val ttl = 20.minutes
47+
4648
private val coll = db(CollName("viewer_count"))
4749

48-
private val cache = cacheApi.notLoading[CountKey, ViewerCount](64, "viewerCount"):
49-
_.expireAfterAccess(20.minutes).buildAsync()
50+
private val cache = cacheApi.notLoading[CountKey, ViewerCount](512, "viewerCount"):
51+
_.expireAfterAccess(ttl).buildAsync()
5052

5153
private def fetch(key: CountKey): Fu[Int] =
5254
coll.primitiveOne[Int]($id(key), "v").dmap(_.orZero)
@@ -65,7 +67,7 @@ final class ViewerCountApi(db: lila.db.Db, cacheApi: CacheApi)(using scheduler:
6567
val viewer = (req.remoteAddress, HTTPRequest.userAgent(req), user)
6668
hit(key, maxCount)(viewer)
6769

68-
scheduler.scheduleWithFixedDelay(2.minutes, 2.minutes): () =>
70+
scheduler.scheduleWithFixedDelay(ttl / 2, ttl / 2): () =>
6971
cache.underlying.synchronous
7072
.asMap()
7173
.forEach: (key, vc) =>

0 commit comments

Comments
 (0)