diff src/lib/Db.luan @ 53:9298b04607ae

add unread
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 03 Mar 2025 19:39:30 -0700
parents f9e6a4cc4f7d
children d21ae4920aac
line wrap: on
line diff
--- a/src/lib/Db.luan	Mon Mar 03 12:29:06 2025 -0700
+++ b/src/lib/Db.luan	Mon Mar 03 19:39:30 2025 -0700
@@ -1,6 +1,7 @@
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
 local new_error = Luan.new_error or error()
+local ipairs = Luan.ipairs or error()
 local Lucene = require "luan:lucene/Lucene.luan"
 local Io = require "luan:Io.luan"
 local uri = Io.uri or error()
@@ -25,12 +26,22 @@
 Db.indexed_fields.chat_updated = Lucene.type.long
 
 Db.indexed_fields.post_chat_id = Lucene.type.long
+Db.indexed_fields.post_date = Lucene.type.long
+
+Db.indexed_fields.chatuser_id = Lucene.type.string
 
 function Db.not_in_transaction()
 	logger.error(new_error("not in transaction"))
 end
 
 Db.update{
+	[1] = function()
+		local docs = Db.search("type:post",1,1000000)
+		for _, doc in ipairs(docs) do
+			doc.post_date = doc.post_date or doc.date
+			Db.save(doc)
+		end
+	end
 }
 
 if Http.is_serving then