Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How would you use GRDBQuery on large data #10

Closed
fbertuzzi opened this issue Feb 5, 2022 · 4 comments
Closed

Question: How would you use GRDBQuery on large data #10

fbertuzzi opened this issue Feb 5, 2022 · 4 comments

Comments

@fbertuzzi
Copy link

Hey,

I'm currently working on a Chat App and using GRDBQuery for data loading from GRDB.

How would you use GRDBQuery for loading chat message?
Currently I'm fetching all messages which starts to cause large loading times and memory usage as it's all getting fetched at once.

The messages are displayed in a ScrollView which embeds a LazyVStack.

How would I use GRDBQuery for fetching just the messages currently needed, but keep the immediate loading GRDBQuery offers.

Is that possible?

@groue
Copy link
Owner

groue commented Feb 6, 2022

Hello @fbertuzzi,

The publisher of your Queryable type can only fetch and publish "the messages currently needed" (whatever it means).

If the definition of "currently needed" changes over time, you can modify the query at runtime. As an inspiration, check this demo app: it changes the ordering of the list fetched by its @Query. You should be able to adapt it in order to change the definition of "currently needed" messages instead of the ordering.

@fbertuzzi
Copy link
Author

Hey @groue,

thank you for the fast reply! I’ll definitely have a look into the demo app. With „currently needed“ I mean which messages are currently in view + some additional ones so the user won’t notice that much of a loading time. If I change my array of messages while scrolling, wouldn’t that mess up my scrollview position as the user is scrolling from the bottom up?

@groue
Copy link
Owner

groue commented Feb 6, 2022

With „currently needed“ I mean which messages are currently in view + some additional ones so the user won’t notice that much of a loading time. If I change my array of messages while scrolling, wouldn’t that mess up my scrollview position as the user is scrolling from the bottom up?

Your question is about the behavior of SwiftUI lists and stacks regarding lists that vary according to pagination or other techniques. This repository is not quite the place to ask such question, I'm sorry. I do wish I had a ready-made answer, but I have not!

@groue groue closed this as completed Feb 6, 2022
@groue
Copy link
Owner

groue commented Feb 6, 2022

I had to close the issue since it is not related to @Query (yet).

But I can give an advice: maybe do not try to tackle all problems at the same time.

I'd explore the subject of varying lists first, without any database or @Query. How does LazyVStack behave when you change a plain array as the user scrolls? Is this SwiftUI view able to do what you need? You'd also be able to grab a precise understanding of what "currently needed" means.

Only then, when I have a clear understanding of the data I need, and how to ask SwiftUI to display it, I'd plug @Query on top of it. If you have questions at this point, please reopen this issue, or create a new one.

Feel free to share your conclusions! This may help other users in the future!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants