mirror of
https://github.com/zedeus/nitter
synced 2026-09-06 07:09:31 +00:00
Store profile usernames in lowercase for speedup
This commit is contained in:
parent
a77c0f6a84
commit
5fc458638d
4 changed files with 19 additions and 12 deletions
|
|
@ -17,6 +17,8 @@ withDb:
|
|||
Video.title.safeAddColumn
|
||||
Video.description.safeAddColumn
|
||||
|
||||
safeAddColumn Profile.lowername
|
||||
|
||||
var profileCacheTime = initDuration(minutes=10)
|
||||
|
||||
proc isOutdated*(profile: Profile): bool =
|
||||
|
|
@ -25,7 +27,7 @@ proc isOutdated*(profile: Profile): bool =
|
|||
proc cache*(profile: var Profile) =
|
||||
withDb:
|
||||
try:
|
||||
let p = Profile.getOne("lower(username) = ?", toLower(profile.username))
|
||||
let p = Profile.getOne("lowername = ?", profile.lowername)
|
||||
profile.id = p.id
|
||||
profile.update()
|
||||
except KeyError:
|
||||
|
|
@ -35,7 +37,7 @@ proc cache*(profile: var Profile) =
|
|||
proc hasCachedProfile*(username: string): Option[Profile] =
|
||||
withDb:
|
||||
try:
|
||||
let p = Profile.getOne("lower(username) = ?", toLower(username))
|
||||
let p = Profile.getOne("lowername = ?", toLower(username))
|
||||
doAssert not p.isOutdated
|
||||
result = some p
|
||||
except AssertionError, KeyError:
|
||||
|
|
@ -45,7 +47,7 @@ proc getCachedProfile*(username, agent: string;
|
|||
force=false): Future[Profile] {.async.} =
|
||||
withDb:
|
||||
try:
|
||||
result.getOne("lower(username) = ?", toLower(username))
|
||||
result.getOne("lowername = ?", toLower(username))
|
||||
doAssert not result.isOutdated
|
||||
except AssertionError, KeyError:
|
||||
result = await getProfileFull(username, agent)
|
||||
|
|
|
|||
Loading…
Reference in a new issue