mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-13 03:26:30 +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.title.safeAddColumn
|
||||||
Video.description.safeAddColumn
|
Video.description.safeAddColumn
|
||||||
|
|
||||||
|
safeAddColumn Profile.lowername
|
||||||
|
|
||||||
var profileCacheTime = initDuration(minutes=10)
|
var profileCacheTime = initDuration(minutes=10)
|
||||||
|
|
||||||
proc isOutdated*(profile: Profile): bool =
|
proc isOutdated*(profile: Profile): bool =
|
||||||
|
@ -25,7 +27,7 @@ proc isOutdated*(profile: Profile): bool =
|
||||||
proc cache*(profile: var Profile) =
|
proc cache*(profile: var Profile) =
|
||||||
withDb:
|
withDb:
|
||||||
try:
|
try:
|
||||||
let p = Profile.getOne("lower(username) = ?", toLower(profile.username))
|
let p = Profile.getOne("lowername = ?", profile.lowername)
|
||||||
profile.id = p.id
|
profile.id = p.id
|
||||||
profile.update()
|
profile.update()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -35,7 +37,7 @@ proc cache*(profile: var Profile) =
|
||||||
proc hasCachedProfile*(username: string): Option[Profile] =
|
proc hasCachedProfile*(username: string): Option[Profile] =
|
||||||
withDb:
|
withDb:
|
||||||
try:
|
try:
|
||||||
let p = Profile.getOne("lower(username) = ?", toLower(username))
|
let p = Profile.getOne("lowername = ?", toLower(username))
|
||||||
doAssert not p.isOutdated
|
doAssert not p.isOutdated
|
||||||
result = some p
|
result = some p
|
||||||
except AssertionError, KeyError:
|
except AssertionError, KeyError:
|
||||||
|
@ -45,7 +47,7 @@ proc getCachedProfile*(username, agent: string;
|
||||||
force=false): Future[Profile] {.async.} =
|
force=false): Future[Profile] {.async.} =
|
||||||
withDb:
|
withDb:
|
||||||
try:
|
try:
|
||||||
result.getOne("lower(username) = ?", toLower(username))
|
result.getOne("lowername = ?", toLower(username))
|
||||||
doAssert not result.isOutdated
|
doAssert not result.isOutdated
|
||||||
except AssertionError, KeyError:
|
except AssertionError, KeyError:
|
||||||
result = await getProfileFull(username, agent)
|
result = await getProfileFull(username, agent)
|
||||||
|
|
|
@ -7,9 +7,11 @@ proc parseTimelineProfile*(node: XmlNode): Profile =
|
||||||
if profile == nil: return
|
if profile == nil: return
|
||||||
|
|
||||||
let pre = ".ProfileHeaderCard-"
|
let pre = ".ProfileHeaderCard-"
|
||||||
|
let username = profile.getUsername(pre & "screenname")
|
||||||
result = Profile(
|
result = Profile(
|
||||||
fullname: profile.getName(pre & "nameLink"),
|
fullname: profile.getName(pre & "nameLink"),
|
||||||
username: profile.getUsername(pre & "screenname"),
|
username: username,
|
||||||
|
lowername: toLower(username),
|
||||||
joinDate: profile.getDate(pre & "joinDateText"),
|
joinDate: profile.getDate(pre & "joinDateText"),
|
||||||
website: profile.selectAttr(pre & "urlText a", "title"),
|
website: profile.selectAttr(pre & "urlText a", "title"),
|
||||||
bio: profile.getBio(pre & "bio"),
|
bio: profile.getBio(pre & "bio"),
|
||||||
|
@ -27,9 +29,11 @@ proc parsePopupProfile*(node: XmlNode; selector=".profile-card"): Profile =
|
||||||
let profile = node.select(selector)
|
let profile = node.select(selector)
|
||||||
if profile == nil: return
|
if profile == nil: return
|
||||||
|
|
||||||
|
let username = profile.getUsername(".username")
|
||||||
result = Profile(
|
result = Profile(
|
||||||
fullname: profile.getName(".fullname"),
|
fullname: profile.getName(".fullname"),
|
||||||
username: profile.getUsername(".username"),
|
username: username,
|
||||||
|
lowername: toLower(username),
|
||||||
bio: profile.getBio(".bio", fallback=".ProfileCard-bio"),
|
bio: profile.getBio(".bio", fallback=".ProfileCard-bio"),
|
||||||
userpic: profile.getAvatar(".ProfileCard-avatarImage"),
|
userpic: profile.getAvatar(".ProfileCard-avatarImage"),
|
||||||
verified: isVerified(profile),
|
verified: isVerified(profile),
|
||||||
|
|
|
@ -15,10 +15,10 @@ withDb:
|
||||||
createTables()
|
createTables()
|
||||||
except DbError:
|
except DbError:
|
||||||
discard
|
discard
|
||||||
Prefs.theme.safeAddColumn
|
safeAddColumn Prefs.theme
|
||||||
Prefs.hidePins.safeAddColumn
|
safeAddColumn Prefs.hidePins
|
||||||
Prefs.hideReplies.safeAddColumn
|
safeAddColumn Prefs.hideReplies
|
||||||
Prefs.infiniteScroll.safeAddColumn
|
safeAddColumn Prefs.infiniteScroll
|
||||||
|
|
||||||
proc getDefaultPrefs(cfg: Config): Prefs =
|
proc getDefaultPrefs(cfg: Config): Prefs =
|
||||||
result = genDefaultPrefs()
|
result = genDefaultPrefs()
|
||||||
|
|
|
@ -12,6 +12,7 @@ dbTypes:
|
||||||
Profile* = object
|
Profile* = object
|
||||||
username*: string
|
username*: string
|
||||||
fullname*: string
|
fullname*: string
|
||||||
|
lowername*: string
|
||||||
location*: string
|
location*: string
|
||||||
website*: string
|
website*: string
|
||||||
bio*: string
|
bio*: string
|
||||||
|
@ -25,9 +26,9 @@ dbTypes:
|
||||||
verified*: bool
|
verified*: bool
|
||||||
protected*: bool
|
protected*: bool
|
||||||
joinDate* {.
|
joinDate* {.
|
||||||
dbType: "INTEGER"
|
dbType: "INTEGER"
|
||||||
parseIt: it.i.fromUnix()
|
parseIt: it.i.fromUnix()
|
||||||
formatIt: dbValue(it.toUnix())
|
formatIt: dbValue(it.toUnix())
|
||||||
.}: Time
|
.}: Time
|
||||||
updated* {.
|
updated* {.
|
||||||
dbType: "INTEGER"
|
dbType: "INTEGER"
|
||||||
|
|
Loading…
Reference in a new issue