tauri-apps / tauri-apps/plugins-workspace
(store) store|reload command has unexpected side-effect (self.cache.extend)
- Dominant language
- Rust
- Stars
- 1.8k
- Forks
- 602
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 9
Description
https://github.com/tauri-apps/plugins-workspace/blob/ca3c3aa28afd302178270df48dc3f6df45fa373b/plugins/store/guest-js/index.ts#L395-L397
As the description of `reload` function suggests, it should load the on-disk state into memory. But what is actually happening is a merge operation (or, using Rust's vocabulary, extending HashMap that is already in memory).
### Example
After changing JSON externally as follows:
```diff
{
"one": {
"someKey": "someValue"
},
- "two": {
+ "three": {
"someKey": "someValue"
}
}
```
Instead of getting cache like this...
```json
{
"one": {
"someKey": "someValue"
},
"three": {
"someKey": "someValue"
}
}
```
...calling `reload` function will result in the following:
```json
{
"one": {
"someKey": "someValue"
},
"two": {
"someKey": "someValue"
},
"three": {
"someKey": "someValue"
}
}
```
## Current implementation
When it comes to `store|load` function, using `cache.extend` is probably fine, but for `store|reload`, given the current description, it makes the current behavior quite confusing.
```ts
await invoke('plugin:store|reload', { rid: this.rid })
```
https://github.com/tauri-apps/plugins-workspace/blob/ca3c3aa28afd302178270df48dc3f6df45fa373b/plugins/store/src/lib.rs#L212-L215
https://github.com/tauri-apps/plugins-workspace/blob/ca3c3aa28afd302178270df48dc3f6df45fa373b/plugins/store/src/store.rs#L502-L504
https://github.com/tauri-apps/plugins-workspace/blob/ca3c3aa28afd302178270df48dc3f6df45fa373b/plugins/store/src/store.rs#L287-L294
## Solutions
Depending on why the current implementation is using `cache.extend`, and assuming that my understanding is correct, I would like to ask, to update the description of `store|reload` and warn about the side-effect (as changing the current implementation [doesn't seem wise](https://xkcd.com/1172/)).
## Question
In the meantime, I have a question. Is there some obvious way I'm missing, to actually update the cache to reflect the on-disk state?
Contributor guide
Assessment
This issue has not been assessed yet.