MobileNativeFoundation / MobileNativeFoundation/Store
[BUG] Cached(refresh = true) will collect SoT reader twice
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 3.4k
- Forks
- 217
- Avg merge
- 18m
- Merged PRs (30d)
- 4
Description
Describe the bug
I'm not completely sure this is a bug, but I can't possibly think of a reason for it to not be a bug, so I'd like to see some confirmation.
When requesting with StoreReadRequest.cached(key = key, refresh = true), SoT reader will get hit twice. This will effectively restart any DB observation and run queries again.
While on most situations this shouldn't be an issue, I have a very particular case where I'm leveraging the scope of the reader flow (using channelFlow) to do some operations while there is someone still collecting it. With this behavior of collecting twice, my scope is getting cancelled and so are the operations.
I really can't think of a reason for it to need to collect twice. I'd hope that when we start .stream, it would collect reader and just stay there.
Using StoreReadRequest.cached(key = key, refresh = false) works without issue.
Is it really a bug? Thanks!
To Reproduce
See above.
Expected behavior
With only one call to .stream, reader should only be collected once.
Screenshots
N/A
Smartphone (please complete the following information):
- Device: N/A
- OS: N/A
- Store Version 5.0.0-beta02
Additional context
N/A
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at StoreReadRequest.cached(key = key, refresh = true) and the .stream entry point, then trace where the SoT reader is collected. Compare this path with refresh = false and add a regression test for one collection. Done means one .stream call collects the reader only once.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100