only update the needed tweets for a given user when they are submitted
This commit is contained in:
parent
313c79f3cc
commit
d5ffe8db52
|
@ -57,18 +57,9 @@ proc getTweetsFrom*(url: string, username: string): seq[Tweet] =
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
proc updateTweetsOnce*() {. gcsafe .} =
|
proc updateTweetsByUser*(db: DBConn, username, url: string) {. gcsafe .} =
|
||||||
var db = open("./data/twtxt.db", nil, nil, nil)
|
|
||||||
|
|
||||||
var users = db.getAllRows sql"select * from users where username != 'twtxtlist'"
|
|
||||||
|
|
||||||
for user in users.items():
|
|
||||||
echo "updating " & $user
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
let
|
let
|
||||||
username = user[1]
|
|
||||||
url = user[2]
|
|
||||||
tweets = getTweetsFrom(url, username)
|
tweets = getTweetsFrom(url, username)
|
||||||
|
|
||||||
for tweet in tweets.items():
|
for tweet in tweets.items():
|
||||||
|
@ -77,3 +68,13 @@ proc updateTweetsOnce*() {. gcsafe .} =
|
||||||
except: discard
|
except: discard
|
||||||
except:
|
except:
|
||||||
echo getCurrentExceptionMsg()
|
echo getCurrentExceptionMsg()
|
||||||
|
|
||||||
|
proc updateTweetsOnce*() {. gcsafe .} =
|
||||||
|
var db = open("./data/twtxt.db", nil, nil, nil)
|
||||||
|
|
||||||
|
var users = db.getAllRows sql"select * from users where username != 'twtxtlist'"
|
||||||
|
|
||||||
|
for user in users.items():
|
||||||
|
echo "updating " & $user
|
||||||
|
|
||||||
|
db.updateTweetsByUser(user[1], user[2])
|
||||||
|
|
|
@ -91,8 +91,7 @@ routes:
|
||||||
username = $(request.formData.mget "username").body
|
username = $(request.formData.mget "username").body
|
||||||
url = $(request.formData.mget "url").body
|
url = $(request.formData.mget "url").body
|
||||||
|
|
||||||
discard url.getTweetsFrom(username)
|
db.updateTweetsByUser(username, url)
|
||||||
|
|
||||||
db.exec(sql"insert into users values (null, ?, ?)", username, url)
|
db.exec(sql"insert into users values (null, ?, ?)", username, url)
|
||||||
|
|
||||||
redirect "/users/" & username & "/0"
|
redirect "/users/" & username & "/0"
|
||||||
|
|
Loading…
Reference in New Issue