MobileNativeFoundation / MobileNativeFoundation/Store

[BUG] Cached(refresh = true) will collect SoT reader twice

Open
#572 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.