only update the needed tweets for a given user when they are submitted
This commit is contained in:
parent
313c79f3cc
commit
d5ffe8db52
|
@ -57,6 +57,18 @@ proc getTweetsFrom*(url: string, username: string): seq[Tweet] =
|
|||
|
||||
return res
|
||||
|
||||
proc updateTweetsByUser*(db: DBConn, username, url: string) {. gcsafe .} =
|
||||
try:
|
||||
let
|
||||
tweets = getTweetsFrom(url, username)
|
||||
|
||||
for tweet in tweets.items():
|
||||
try:
|
||||
db.exec(sql"insert into tweets values(null, ?, ?, ?);", username, tweet.date.timeInfoToTime().toSeconds().int(), tweet.message)
|
||||
except: discard
|
||||
except:
|
||||
echo getCurrentExceptionMsg()
|
||||
|
||||
proc updateTweetsOnce*() {. gcsafe .} =
|
||||
var db = open("./data/twtxt.db", nil, nil, nil)
|
||||
|
||||
|
@ -65,15 +77,4 @@ proc updateTweetsOnce*() {. gcsafe .} =
|
|||
for user in users.items():
|
||||
echo "updating " & $user
|
||||
|
||||
try:
|
||||
let
|
||||
username = user[1]
|
||||
url = user[2]
|
||||
tweets = getTweetsFrom(url, username)
|
||||
|
||||
for tweet in tweets.items():
|
||||
try:
|
||||
db.exec(sql"insert into tweets values(null, ?, ?, ?);", username, tweet.date.timeInfoToTime().toSeconds().int(), tweet.message)
|
||||
except: discard
|
||||
except:
|
||||
echo getCurrentExceptionMsg()
|
||||
db.updateTweetsByUser(user[1], user[2])
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue