summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-10-31 16:43:59 +0600
committerunwox <me@unwox.com>2024-10-31 16:57:36 +0600
commitcfeb4f60d7429c501e2fba4a53b5bbd0b4f0b5b3 (patch)
tree94253aa6a2b8da8871baf21944d570e6e395fe88 /bin
parentb42c52ae2de08c1104c2677a36536c37e83e7ad6 (diff)
pick products for front page based on the day and not randomly
Diffstat (limited to 'bin')
-rw-r--r--bin/serve.fnl55
1 files changed, 33 insertions, 22 deletions
diff --git a/bin/serve.fnl b/bin/serve.fnl
index 69369fe..c8fc6f2 100644
--- a/bin/serve.fnl
+++ b/bin/serve.fnl
@@ -124,25 +124,39 @@
"&price-per=on"
"")))
-(fn random-products [limit]
+(fn teas-of-the-day [limit]
(assert (< 0 limit) "limit must be > 0")
+ (local the-number (* (tonumber (os.date "%Y%m%d")) limit))
+ (local total
+ (. (must (luna.db.query db
+ "SELECT count(*)
+ FROM products
+ INNER JOIN product_tags ON product_tags.product = products.url
+ WHERE archived = false
+ AND product_tags.tag IN ('Красный чай', 'Улун', 'Шен пуэр',
+ 'Шу пуэр', 'Зеленый чай', 'Белый чай',
+ 'Желтый чай')" []))
+ 1 1))
(must
- (luna.db.query*
- db
- "SELECT site,
- title,
- description,
- image,
- url,
- price,
- weight,
- price_per AS \"price-per\",
- year
+ (luna.db.query*
+ db
+ "SELECT products.site,
+ products.title,
+ products.description,
+ products.image,
+ products.url,
+ products.price,
+ products.weight,
+ products.price_per AS \"price-per\"
FROM products
- WHERE archived = false
- ORDER BY ROW_NUMBER() over (PARTITION BY site ORDER BY ROWID)
- LIMIT ?"
- [limit])))
+ INNER JOIN product_tags ON product_tags.product = products.url
+ WHERE products.archived = false
+ AND product_tags.tag IN ('Красный чай', 'Улун', 'Шен пуэр', 'Шу пуэр',
+ 'Зеленый чай', 'Белый чай', 'Желтый чай')
+ ORDER BY ROW_NUMBER() over (PARTITION BY site ORDER BY products.ROWID)
+ LIMIT ?
+ OFFSET ?"
+ [limit (% the-number (- total limit))])))
(fn all-tags []
(map
@@ -220,10 +234,7 @@
products.url,
products.price,
products.weight,
- products.price_per AS \"price-per\",
- products.year,
- products.archived,
- products.creation_time AS \"creation-time\"
+ products.price_per AS \"price-per\"
FROM search
INNER JOIN products ON search.fid = products.url
LEFT JOIN product_tags ON product_tags.product = products.url
@@ -319,7 +330,7 @@
:autofocus true :placeholder "Поисковый запрос"}]
[:div {}
[:select {:name "tags"}
- [:option {:value ""} "~ Категория ~"]
+ [:option {:value ""} "~ Тег ~"]
(table.unpack
(map
(fn [_ tag]
@@ -416,7 +427,7 @@
{: results : total}
(if (not (form-empty? form))
(query-products form page)
- {:total 48 :results (random-products 48)})]
+ {:total 10 :results (teas-of-the-day 10)})]
(values
200 headers
(cache.set db cache-key