summaryrefslogtreecommitdiff
path: root/angelsharkd/src/routes/extensions
diff options
context:
space:
mode:
authorCarpenter, Adam (CORP) <adam.carpenter@adp.com>2021-11-26 16:06:17 -0500
committerCarpenter, Adam (CORP) <adam.carpenter@adp.com>2021-11-26 16:06:17 -0500
commit3acf604c92b64032885ef27d225efa1307a015ad (patch)
treec948965451fd2985649a6bda977b3aed69452cec /angelsharkd/src/routes/extensions
parent6dd3236069d5cbdd6cb946b408cd6efb7e91d0f9 (diff)
downloadaltruistic-angelshark-3acf604c92b64032885ef27d225efa1307a015ad.tar.xz
altruistic-angelshark-3acf604c92b64032885ef27d225efa1307a015ad.zip
feat: impl lazy-refreshing cache for quick access to be used for haystack
Diffstat (limited to 'angelsharkd/src/routes/extensions')
-rw-r--r--angelsharkd/src/routes/extensions/simple_search.rs31
1 files changed, 19 insertions, 12 deletions
diff --git a/angelsharkd/src/routes/extensions/simple_search.rs b/angelsharkd/src/routes/extensions/simple_search.rs
index 58f6e52..cf75c60 100644
--- a/angelsharkd/src/routes/extensions/simple_search.rs
+++ b/angelsharkd/src/routes/extensions/simple_search.rs
@@ -24,33 +24,40 @@ pub fn search(config: &Config) -> impl Filter<Extract = impl Reply, Error = Reje
.and_then(handle_simple_search)
}
-pub fn refresh() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
+pub fn refresh(config: &Config) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
+ let runner = config.runner.clone();
path!("search" / "refresh")
.and(get())
+ .and(with_runner(runner))
.and_then(handle_refresh)
}
-async fn handle_refresh() -> Result<impl Reply, Infallible> {
- fetch(String::from("test"), true);
- Ok("")
+async fn handle_refresh(runner: AcmRunner) -> Result<impl Reply, Infallible> {
+ get_extensions_cached(true);
+ Ok("Refresh scheduled")
}
async fn handle_simple_search(terms: Terms, runner: AcmRunner) -> Result<impl Reply, Infallible> {
- Ok(fetch(terms[0].clone(), false))
+ Ok(get_extensions_cached(false))
}
#[cached]
-fn fetch(param: String, refresh: bool) -> String {
+fn get_extensions_cached(refresh: bool) -> String {
if refresh {
- let param = param.clone();
tokio::spawn(async move {
std::thread::sleep_ms(10000);
- let mut handle = FETCH.lock().unwrap();
- handle.cache_clear();
- handle.cache_set((param.clone(), false), format!("blargh {}", param.clone()));
- eprintln!("evicted");
+
+ if let Ok(mut handle) = GET_EXTENSIONS_CACHED.lock() {
+ handle.cache_clear();
+ handle.cache_set(false, String::from("fresh"));
+ eprintln!("evicted");
+ }
});
}
- param
+ String::from("stale")
+}
+
+fn get_extensions(runner: AcmRunner) {
+ todo!()
}