mirror of
https://github.com/zedeus/nitter
synced 2026-09-06 07:09:31 +00:00
Add periodic cache cleaner prevent slowdowns
This commit is contained in:
parent
211cd5964a
commit
8c50692299
3 changed files with 22 additions and 7 deletions
|
|
@ -10,12 +10,9 @@ template safeAddColumn(field: typedesc): untyped =
|
|||
dbFromTypes("cache.db", "", "", "", [Profile, Video])
|
||||
|
||||
withDb:
|
||||
try:
|
||||
createTables()
|
||||
except DbError:
|
||||
discard
|
||||
Video.title.safeAddColumn
|
||||
Video.description.safeAddColumn
|
||||
Video.createTable(force=true)
|
||||
try: Profile.createTable()
|
||||
except DbError: discard
|
||||
|
||||
safeAddColumn Profile.lowername
|
||||
|
||||
|
|
@ -80,3 +77,14 @@ proc getCachedVideo*(id: int64): Option[Video] =
|
|||
return some Video.getOne("videoId = ?", $id)
|
||||
except KeyError:
|
||||
return none Video
|
||||
|
||||
proc cacheCleaner*() {.async.} =
|
||||
while true:
|
||||
await sleepAsync(profileCacheTime.inMilliseconds.int)
|
||||
withDb:
|
||||
let up = "updated<" & $toUnix(getTime() - profileCacheTime)
|
||||
var profiles = Profile.getMany(10000, cond=up)
|
||||
var videos = Video.getMany(10000, cond=up)
|
||||
transaction:
|
||||
for p in profiles.mitems: delete(p)
|
||||
for v in videos.mitems: delete(v)
|
||||
|
|
|
|||
Loading…
Reference in a new issue