mirror of https://github.com/velour/catbase.git
Compare commits
2 Commits
3a4d69bae0
...
a31d2b446e
Author | SHA1 | Date |
---|---|---|
Chris Sexton | a31d2b446e | |
Chris Sexton | 4b749d316d |
|
@ -57,6 +57,7 @@ type Bid struct {
|
||||||
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()
|
||||||
|
|
Loading…
Reference in New Issue