Use random user agents

This commit is contained in:
Zed
2019-07-31 08:36:24 +02:00
parent d0ee8e8403
commit 6b6e5b3a40
4 changed files with 143 additions and 53 deletions

View File

@@ -12,18 +12,18 @@ var profileCacheTime = initDuration(minutes=10)
proc outdated(profile: Profile): bool =
getTime() - profile.updated > profileCacheTime
proc getCachedProfile*(username: string; force=false): Future[Profile] {.async.} =
proc getCachedProfile*(username, agent: string; force=false): Future[Profile] {.async.} =
withDb:
try:
result.getOne("username = ?", username)
doAssert not result.outdated()
except AssertionError:
var profile = await getProfile(username)
var profile = await getProfile(username, agent)
profile.id = result.id
result = profile
result.update()
except KeyError:
result = await getProfile(username)
result = await getProfile(username, agent)
if result.username.len > 0:
result.insert()