mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-12 02:56:29 +00:00
Fix profile caching logic to ignore empty profiles
This commit is contained in:
parent
cd4840363c
commit
384b0a2033
2 changed files with 8 additions and 6 deletions
|
@ -63,7 +63,7 @@ proc cache*(data: PhotoRail; name: string) {.async.} =
|
||||||
await setex("pr:" & name, baseCacheTime, compress(freeze(data)))
|
await setex("pr:" & name, baseCacheTime, compress(freeze(data)))
|
||||||
|
|
||||||
proc cache*(data: Profile) {.async.} =
|
proc cache*(data: Profile) {.async.} =
|
||||||
if data.username.len == 0: return
|
if data.username.len == 0 or data.id.len == 0: return
|
||||||
let name = toLower(data.username)
|
let name = toLower(data.username)
|
||||||
pool.withAcquire(r):
|
pool.withAcquire(r):
|
||||||
r.startPipelining()
|
r.startPipelining()
|
||||||
|
@ -93,14 +93,12 @@ proc getProfileId*(username: string): Future[string] {.async.} =
|
||||||
if result == redisNil:
|
if result == redisNil:
|
||||||
result.setLen(0)
|
result.setLen(0)
|
||||||
|
|
||||||
proc getCachedProfile*(username: string; fetch=true;
|
proc getCachedProfile*(username: string; fetch=true): Future[Profile] {.async.} =
|
||||||
cache=false): Future[Profile] {.async.} =
|
|
||||||
let prof = await get("p:" & toLower(username))
|
let prof = await get("p:" & toLower(username))
|
||||||
if prof != redisNil:
|
if prof != redisNil:
|
||||||
uncompress(prof).thaw(result)
|
uncompress(prof).thaw(result)
|
||||||
elif fetch:
|
elif fetch:
|
||||||
result = await getProfile(username)
|
result = await getProfile(username)
|
||||||
if cache: await cache(result)
|
|
||||||
|
|
||||||
proc getCachedPhotoRail*(name: string): Future[PhotoRail] {.async.} =
|
proc getCachedPhotoRail*(name: string): Future[PhotoRail] {.async.} =
|
||||||
if name.len == 0: return
|
if name.len == 0: return
|
||||||
|
|
|
@ -31,7 +31,10 @@ proc fetchSingleTimeline*(after: string; query: Query; skipRail=false):
|
||||||
profile = await getCachedProfile(name)
|
profile = await getCachedProfile(name)
|
||||||
profileId = if profile.suspended: "s"
|
profileId = if profile.suspended: "s"
|
||||||
else: profile.id
|
else: profile.id
|
||||||
await cacheProfileId(profile.username, profileId)
|
|
||||||
|
if profileId.len > 0:
|
||||||
|
await cacheProfileId(profile.username, profileId)
|
||||||
|
|
||||||
fetched = true
|
fetched = true
|
||||||
|
|
||||||
if profileId.len == 0 or profile.protected:
|
if profileId.len == 0 or profile.protected:
|
||||||
|
@ -66,7 +69,8 @@ proc fetchSingleTimeline*(after: string; query: Query; skipRail=false):
|
||||||
break
|
break
|
||||||
|
|
||||||
if profile.username.len == 0:
|
if profile.username.len == 0:
|
||||||
profile = await getCachedProfile(name, cache=true)
|
profile = await getCachedProfile(name)
|
||||||
|
fetched = true
|
||||||
|
|
||||||
if fetched and not found:
|
if fetched and not found:
|
||||||
await cache(profile)
|
await cache(profile)
|
||||||
|
|
Loading…
Reference in a new issue