Compare commits

...

2 Commits

Author SHA1 Message Date
Chris Sexton a31d2b446e go fmt 2019-11-08 10:20:01 -05:00
Chris Sexton 4b749d316d bids: mark bids instead of deleting them 2019-11-08 10:20:01 -05:00
1 changed files with 13 additions and 11 deletions

View File

@ -51,12 +51,13 @@ func (s Stories) Titles() string {
} }
type Bid struct { type Bid struct {
ID int ID int
User string User string
Title string Title string
URL string URL string
Bid int Bid int
Placed int64 Placed int64
Processed int64
} }
func (b Bid) PlacedParsed() time.Time { func (b Bid) PlacedParsed() time.Time {
@ -96,6 +97,7 @@ func (w *Webshit) setup() {
url string, url string,
bid integer, bid integer,
placed integer placed integer
processed integer
)`) )`)
w.db.MustExec(`create table if not exists webshit_balances ( w.db.MustExec(`create table if not exists webshit_balances (
user string primary key, user string primary key,
@ -111,7 +113,7 @@ func (w *Webshit) Check() ([]WeeklyResult, error) {
} }
var bids []Bid var bids []Bid
if err = w.db.Select(&bids, `select user,title,url,bid from webshit_bids where placed < ?`, if err = w.db.Select(&bids, `select user,title,url,bid from webshit_bids where placed < ? and processed=0`,
published.Unix()); err != nil { published.Unix()); err != nil {
return nil, err return nil, err
} }
@ -140,8 +142,8 @@ func (w *Webshit) Check() ([]WeeklyResult, error) {
} }
// Delete all those bids // Delete all those bids
if _, err = w.db.Exec(`delete from webshit_bids where placed < ?`, if _, err = w.db.Exec(`update webshit_bids set processed=? where placed < ?`,
published.Unix()); err != nil { time.Now().Unix(), published.Unix()); err != nil {
return nil, err return nil, err
} }
@ -279,7 +281,7 @@ func (w *Webshit) GetScore(user string) int {
func (w *Webshit) GetAllBids() ([]Bid, error) { func (w *Webshit) GetAllBids() ([]Bid, error) {
var bids []Bid var bids []Bid
err := w.db.Select(&bids, `select * from webshit_bids`) err := w.db.Select(&bids, `select * from webshit_bids where processed=0`)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -312,7 +314,7 @@ func (w *Webshit) Bid(user string, amount int, URL string) (Bid, error) {
ts := time.Now().Unix() ts := time.Now().Unix()
tx := w.db.MustBegin() tx := w.db.MustBegin()
_, err = tx.Exec(`insert into webshit_bids (user,title,url,bid,placed) values (?,?,?,?,?)`, _, err = tx.Exec(`insert into webshit_bids (user,title,url,bid,placed,processed) values (?,?,?,?,?,0)`,
user, story.Title, story.URL, amount, ts) user, story.Title, story.URL, amount, ts)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()