From e0e990a248e3a18f88d7a12f3c353b8664bd6898 Mon Sep 17 00:00:00 2001 From: unwox Date: Wed, 30 Oct 2024 12:28:41 +0600 Subject: archive old products and do not display them --- bin/fetch.fnl | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'bin/fetch.fnl') 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))) -- cgit v1.2.3