Skip to content

Commit 32ac379

Browse files
ricopinazogithub-actions[bot]
authored andcommitted
trigger graphql cache eviction automatically (#2454)
* trigger graphql cache eviction automatically * fix typo * add fixme for the evicion test * chore: apply tidy-public auto-fixes --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 7e5a1e6 commit 32ac379

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

raphtory-graphql/src/data.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) fn get_relative_path(
5555
#[derive(Clone)]
5656
pub struct Data {
5757
pub(crate) work_dir: PathBuf,
58-
cache: Cache<PathBuf, GraphWithVectors>,
58+
pub(crate) cache: Cache<PathBuf, GraphWithVectors>,
5959
pub(crate) create_index: bool,
6060
pub(crate) embedding_conf: Option<EmbeddingConf>,
6161
}
@@ -414,6 +414,14 @@ pub(crate) mod data_tests {
414414
sleep(Duration::from_secs(3)).await;
415415
assert!(!data.cache.contains_key(Path::new("test_g")));
416416
assert!(!data.cache.contains_key(Path::new("test_g2")));
417+
// FIXME: this test is not doing anything because calling cache.contains_key() runs
418+
// any pending evictions. To actually test it we need this assertion:
419+
// assert_eq!(data.cache.entry_count(), 0);
420+
// Which currently does not work because the server task to trigger evictions is not running
421+
// in this context. The problem is if we do run it by creating a server and calling
422+
// server.start() the server gets consumed and we loose access to the cache to be able to run
423+
// the check. If rework the server implementation and this becomes feasible we should change
424+
// this test
417425
}
418426

419427
#[tokio::test]

raphtory-graphql/src/server.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ impl GraphServer {
200200
self.data.vectorise_all_graphs_that_are_not().await?;
201201
let work_dir = self.data.work_dir.clone();
202202

203+
// Otherwise evictions are only triggered when the cache is actively touched
204+
let cache_clone = self.data.cache.clone();
205+
tokio::spawn(async move {
206+
let mut interval = tokio::time::interval(std::time::Duration::from_secs(1));
207+
loop {
208+
interval.tick().await;
209+
cache_clone.run_pending_tasks().await;
210+
}
211+
});
212+
203213
// it is important that this runs after algorithms have been pushed to PLUGIN_ALGOS static variable
204214
let app = self
205215
.generate_endpoint(tp.clone().map(|tp| tp.tracer(tracer_name)))

0 commit comments

Comments
 (0)