|
37 | 37 | ) |
38 | 38 |
|
39 | 39 |
|
40 | | -class SearchBackgroundUpdateStore(SQLBaseStore): |
| 40 | +class SearchWorkerStore(SQLBaseStore): |
| 41 | + def store_search_entries_txn(self, txn, entries): |
| 42 | + """Add entries to the search table |
| 43 | +
|
| 44 | + Args: |
| 45 | + txn (cursor): |
| 46 | + entries (iterable[SearchEntry]): |
| 47 | + entries to be added to the table |
| 48 | + """ |
| 49 | + if not self.hs.config.enable_search: |
| 50 | + return |
| 51 | + if isinstance(self.database_engine, PostgresEngine): |
| 52 | + sql = ( |
| 53 | + "INSERT INTO event_search" |
| 54 | + " (event_id, room_id, key, vector, stream_ordering, origin_server_ts)" |
| 55 | + " VALUES (?,?,?,to_tsvector('english', ?),?,?)" |
| 56 | + ) |
| 57 | + |
| 58 | + args = ( |
| 59 | + ( |
| 60 | + entry.event_id, |
| 61 | + entry.room_id, |
| 62 | + entry.key, |
| 63 | + entry.value, |
| 64 | + entry.stream_ordering, |
| 65 | + entry.origin_server_ts, |
| 66 | + ) |
| 67 | + for entry in entries |
| 68 | + ) |
| 69 | + |
| 70 | + txn.executemany(sql, args) |
| 71 | + |
| 72 | + elif isinstance(self.database_engine, Sqlite3Engine): |
| 73 | + sql = ( |
| 74 | + "INSERT INTO event_search (event_id, room_id, key, value)" |
| 75 | + " VALUES (?,?,?,?)" |
| 76 | + ) |
| 77 | + args = ( |
| 78 | + (entry.event_id, entry.room_id, entry.key, entry.value) |
| 79 | + for entry in entries |
| 80 | + ) |
| 81 | + |
| 82 | + txn.executemany(sql, args) |
| 83 | + else: |
| 84 | + # This should be unreachable. |
| 85 | + raise Exception("Unrecognized database engine") |
| 86 | + |
| 87 | + |
| 88 | +class SearchBackgroundUpdateStore(SearchWorkerStore): |
41 | 89 |
|
42 | 90 | EVENT_SEARCH_UPDATE_NAME = "event_search" |
43 | 91 | EVENT_SEARCH_ORDER_UPDATE_NAME = "event_search_order" |
@@ -296,52 +344,6 @@ def reindex_search_txn(txn): |
296 | 344 |
|
297 | 345 | return num_rows |
298 | 346 |
|
299 | | - def store_search_entries_txn(self, txn, entries): |
300 | | - """Add entries to the search table |
301 | | -
|
302 | | - Args: |
303 | | - txn (cursor): |
304 | | - entries (iterable[SearchEntry]): |
305 | | - entries to be added to the table |
306 | | - """ |
307 | | - if not self.hs.config.enable_search: |
308 | | - return |
309 | | - if isinstance(self.database_engine, PostgresEngine): |
310 | | - sql = ( |
311 | | - "INSERT INTO event_search" |
312 | | - " (event_id, room_id, key, vector, stream_ordering, origin_server_ts)" |
313 | | - " VALUES (?,?,?,to_tsvector('english', ?),?,?)" |
314 | | - ) |
315 | | - |
316 | | - args = ( |
317 | | - ( |
318 | | - entry.event_id, |
319 | | - entry.room_id, |
320 | | - entry.key, |
321 | | - entry.value, |
322 | | - entry.stream_ordering, |
323 | | - entry.origin_server_ts, |
324 | | - ) |
325 | | - for entry in entries |
326 | | - ) |
327 | | - |
328 | | - txn.executemany(sql, args) |
329 | | - |
330 | | - elif isinstance(self.database_engine, Sqlite3Engine): |
331 | | - sql = ( |
332 | | - "INSERT INTO event_search (event_id, room_id, key, value)" |
333 | | - " VALUES (?,?,?,?)" |
334 | | - ) |
335 | | - args = ( |
336 | | - (entry.event_id, entry.room_id, entry.key, entry.value) |
337 | | - for entry in entries |
338 | | - ) |
339 | | - |
340 | | - txn.executemany(sql, args) |
341 | | - else: |
342 | | - # This should be unreachable. |
343 | | - raise Exception("Unrecognized database engine") |
344 | | - |
345 | 347 |
|
346 | 348 | class SearchStore(SearchBackgroundUpdateStore): |
347 | 349 | def __init__(self, database: Database, db_conn, hs): |
|
0 commit comments