diff options
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/fetch.fnl | 18 | ||||
| -rw-r--r-- | bin/serve.fnl | 3 |
2 files changed, 18 insertions, 3 deletions
diff --git a/bin/fetch.fnl b/bin/fetch.fnl index 4558c50..a3155a4 100644 --- a/bin/fetch.fnl +++ b/bin/fetch.fnl @@ -98,11 +98,12 @@ (fn store-products [tx products] (when (< 0 (# products)) (local sql - (.. "INSERT OR IGNORE INTO products VALUES " + (.. "INSERT OR REPLACE INTO products VALUES " (array.join (map (fn [_ _] "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") products) ", "))) + (local creation-time (now)) (local vars (reduce (fn [_ product rest] @@ -117,7 +118,7 @@ (or product.weight 0) (or product.price-per 0) false - (now)])) + creation-time])) products [])) (must (luna.db.exec-tx tx sql vars)) @@ -125,7 +126,18 @@ (store-tags tx (array.unique (array.flatten (map (fn [_ v] v.tags) products)))) - (store-product-tags tx products))) + (store-product-tags tx products) + + ;; archive previous products + (local site (. products 1 :site)) + (when site + (must (luna.db.exec-tx + tx + "UPDATE products + SET archived = true + WHERE site = ? + AND creation_time < ?" + [site creation-time]))))) (fn populate-search-table [] (local tx (must (luna.db.begin db))) diff --git a/bin/serve.fnl b/bin/serve.fnl index 98e0aac..82759b8 100644 --- a/bin/serve.fnl +++ b/bin/serve.fnl @@ -139,6 +139,7 @@ price_per AS \"price-per\", year FROM products + WHERE archived = false ORDER BY ROW_NUMBER() over (PARTITION BY site ORDER BY ROWID) LIMIT ?" [limit]))) @@ -201,6 +202,7 @@ INNER JOIN products ON search.fid = products.url LEFT JOIN product_tags ON product_tags.product = search.fid WHERE search.`table` = 'products' + AND products.archived = false %s" where-sql) where-vars))) @@ -224,6 +226,7 @@ INNER JOIN products ON search.fid = products.url LEFT JOIN product_tags ON product_tags.product = products.url WHERE search.`table` = 'products' + AND products.archived = false %s ORDER BY ROW_NUMBER() over (PARTITION BY products.site ORDER BY products.ROWID), rank |
