diff options
| author | horus | 2018-02-19 22:53:26 +0100 |
|---|---|---|
| committer | horus | 2018-02-19 22:53:26 +0100 |
| commit | 13b1e31cb91f5af98951f4353d49429f356d7f12 (patch) | |
| tree | 9831f50adbddf945649f256b5cfb86f30e764086 /crawler/database.go | |
| parent | dd48edbc9834eef46b6590439a61c7fa0242c8db (diff) | |
| download | alkobote-13b1e31cb91f5af98951f4353d49429f356d7f12.tar.gz | |
Saving scraped offers runs in Tx. (crawler)
Diffstat (limited to 'crawler/database.go')
| -rw-r--r-- | crawler/database.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/crawler/database.go b/crawler/database.go index c5e2291..d617722 100644 --- a/crawler/database.go +++ b/crawler/database.go @@ -92,7 +92,7 @@ func (app *App) save_offer(W []Angebot) error { query := `INSERT INTO angebot (shop, name, url, abv, volume, age, original_price, discounted_price, base_price, valid_until, image_url, website_raw, spirit_type, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` - stmt, err := app.DB.Prepare(query) + stmt, err := app.Tx.Prepare(query) if err != nil { Debug(err, "Save Offer: Preparing query failed") return err @@ -109,7 +109,7 @@ func (app *App) save_offer(W []Angebot) error { // resembles UNIQUE constraint detect_duplicate_query := fmt.Sprintf(`SELECT 1 FROM _intern_view WHERE name = ? AND shop_id = %d AND volume = %4.2f AND abv = %4.2f AND original_price = %d AND discounted_price = %d AND valid_until = %d`, o.Shop, o.Volume, o.Abv, o.Original_price, o.Discounted_price, o.Valid_until) - err := app.DB.QueryRow(detect_duplicate_query, o.Name).Scan(&found) + err := app.Tx.QueryRow(detect_duplicate_query, o.Name).Scan(&found) if err == sql.ErrNoRows { @@ -144,7 +144,7 @@ func (app *App) remove_expired(W []Angebot, shop Shop) error { query := `SELECT id, name, shop, volume, abv, original_price, discounted_price FROM angebot WHERE shop = ? AND created_at < ? AND (valid_until = 0 OR valid_until > ?)` - rows, err := app.DB.Queryx(query, shop.Id, app.Now, app.Now) + rows, err := app.Tx.Queryx(query, shop.Id, app.Now, app.Now) if err != nil { Debug(err, "Remove expired: Query failed") return err @@ -163,7 +163,7 @@ func (app *App) remove_expired(W []Angebot, shop Shop) error { if !app.offer_contains(W, offer_db) { DebugOffer(offer_db, "Contains not - Set to expire") expire_query := `UPDATE angebot SET valid_until = ? WHERE id = ?` - _, err = app.DB.Exec(expire_query, app.Now, offer_db.Id) + _, err = app.Tx.Exec(expire_query, app.Now, offer_db.Id) if err != nil { offer_db.error_msg = err.Error() offer_db.error_ctx = fmt.Sprintf("UPDATE angebot SET valid_until = %d WHERE id = %d", app.Now, offer_db.Id) |
