about summary refs log tree commit diff
path: root/src/db.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-04-14T20·05+0200
committerVincent Ambo <github@tazj.in>2018-04-14T20·21+0200
commit39d1cd64bc5ffe250dc2a30d05d0b6312e7abbc1 (patch)
tree8b364010a51f01e1df06908f403162b5ffceddbf /src/db.rs
parent3e5b1098c6ae2852ea2df37b7c292cb37d5b1e84 (diff)
feat(main/db): Schedule regular search view refresh
Schedules refreshes of the database view used for search at one-minute
intervals.
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/db.rs b/src/db.rs
index 416e3fdd0f52..a4f86977c5f4 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -177,3 +177,24 @@ impl Handler<SearchPosts> for DbExecutor {
         Ok(search_results)
     }
 }
+
+/// Message that triggers a refresh of the view used for full-text
+/// searching.
+pub struct RefreshSearchView;
+
+impl Message for RefreshSearchView {
+    type Result = Result<()>;
+}
+
+const REFRESH_QUERY: &'static str = "REFRESH MATERIALIZED VIEW search_index";
+
+impl Handler<RefreshSearchView> for DbExecutor {
+    type Result = Result<()>;
+
+    fn handle(&mut self, _: RefreshSearchView, _: &mut Self::Context) -> Self::Result {
+        let conn = self.0.get()?;
+        debug!("Refreshing search_index view in DB");
+        sql_query(REFRESH_QUERY).execute(&conn)?;
+        Ok(())
+    }
+}