only update the needed tweets for a given user when they are submitted

This commit is contained in:
Christine Dodrill 2016-02-10 10:50:01 -08:00
parent 313c79f3cc
commit d5ffe8db52
2 changed files with 14 additions and 14 deletions

View File

@ -57,18 +57,9 @@ proc getTweetsFrom*(url: string, username: string): seq[Tweet] =
return res
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
proc updateTweetsByUser*(db: DBConn, username, url: string) {. gcsafe .} =
try:
let
username = user[1]
url = user[2]
tweets = getTweetsFrom(url, username)
for tweet in tweets.items():
@ -77,3 +68,13 @@ proc updateTweetsOnce*() {. gcsafe .} =
except: discard
except:
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])

View File

@ -91,8 +91,7 @@ routes:
username = $(request.formData.mget "username").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)
redirect "/users/" & username & "/0"