annotate src/lib/Db.luan @ 35:27c41f22d2a9

improve fixPosts
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 12 Nov 2024 17:17:59 -0700
parents f9e6a4cc4f7d
children 9298b04607ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local new_error = Luan.new_error or error()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Lucene = require "luan:lucene/Lucene.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Io = require "luan:Io.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local uri = Io.uri or error()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Http = require "luan:http/Http.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Thread = require "luan:Thread.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Time = require "luan:Time.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local Logging = require "luan:logging/Logging.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local logger = Logging.logger "Db"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 local dir = uri("site:/private/local/lucene")
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local Db = Lucene.index( dir, {
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 log_dir = uri("site:/private/local/lucene_log")
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 name = "lucene"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 version = 1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 } )
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 Db.indexed_fields.user_email = Lucene.type.lowercase
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23
4
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
24 Db.indexed_fields.chat_user_ids = Lucene.type.long
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
25 Db.indexed_fields.chat_updated = Lucene.type.long
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
26
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
27 Db.indexed_fields.post_chat_id = Lucene.type.long
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
28
2
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 function Db.not_in_transaction()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 logger.error(new_error("not in transaction"))
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 Db.update{
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 }
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 if Http.is_serving then
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 Thread.schedule( Db.check, { delay=0, repeating_delay=Time.period{hours=1} } )
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 return Db