From 5c1ebc22afecfbeee02dcb18bcfa0128523b5a93 Mon Sep 17 00:00:00 2001 From: Christopher Biscardi Date: Sun, 13 Sep 2020 00:15:10 -0700 Subject: [PATCH 1/2] update on_demand_inputs invalidation --- book/src/common_patterns/on_demand_inputs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/common_patterns/on_demand_inputs.md b/book/src/common_patterns/on_demand_inputs.md index 77fb3af7..133c9772 100644 --- a/book/src/common_patterns/on_demand_inputs.md +++ b/book/src/common_patterns/on_demand_inputs.md @@ -38,7 +38,7 @@ struct MyDatabase { ... } impl FileWatcher for MyDatabase { fn watch(&self, path: &Path) { ... } fn did_change_file(&mut self, path: &Path) { - self.query_mut(ReadQuery).invalidate(path); + ReadQuery.in_db_mut(self).invalidate(path); } } ``` From c17778e358adaadab9b66a76cc0b165722a4f325 Mon Sep 17 00:00:00 2001 From: Christopher Biscardi Date: Sun, 1 Nov 2020 12:23:17 -0800 Subject: [PATCH 2/2] add links --- book/src/common_patterns/on_demand_inputs.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/book/src/common_patterns/on_demand_inputs.md b/book/src/common_patterns/on_demand_inputs.md index 133c9772..4d58e5c8 100644 --- a/book/src/common_patterns/on_demand_inputs.md +++ b/book/src/common_patterns/on_demand_inputs.md @@ -43,7 +43,9 @@ impl FileWatcher for MyDatabase { } ``` -* We declare the query as a derived query (which is the default). -* In the query implementation, we don't call any other query and just directly read file from disk. -* Because the query doesn't read any inputs, it will be assigned a `HIGH` durability by default, which we override with `report_synthetic_read`. -* The result of the query is cached, and we must call `invalidate` to clear this cache. +- We declare the query as a derived query (which is the default). +- In the query implementation, we don't call any other query and just directly read file from disk. +- Because the query doesn't read any inputs, it will be assigned a `HIGH` durability by default, which we override with `report_synthetic_read`. +- The result of the query is cached, and we must call `invalidate` to clear this cache. + +A complete, runnable file-watching example can be found in [this git repo](https://github.com/ChristopherBiscardi/salsa-file-watch-example/blob/f968dc8ea13a90373f91d962f173de3fe6ae24cd/main.rs) along with [a write-up](https://www.christopherbiscardi.com/on-demand-lazy-inputs-for-incremental-computation-in-salsa-with-file-watching-powered-by-notify-in-rust) that explains more about the code and what it is doing.