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
Flutter, Moor and WorkManager #637
Comments
I don't have a lot of experience writing Flutter apps with background work. But if the process dies, the
Note that the only real threading issue is that sqlite migrations can't run in a transaction. In the case that you create or upgrade the same database at roughly the same time, inconsistencies can occur. So if your WorkManager doesn't do migrations and you don't need real-time synchronization to the UI, you can safely open the database twice without spawning another isolate. Considering battery life, you probably don't want a persistent isolate running all the time (not like Android would allow that). It looks like the |
We are using sqflite in production where we are experiencing weird issue. Long story short, everything looks like it is "threading" issue where one isolate does'nt flush content to the database file or one isolate flushes over data changed in another isolate - but even trasactions are commited without errors. It just looks like that database restores sometimes to and older state. We started migration to moor mainly because of this problem - we can bypass sqflight and even SDK thanks to amazing moor_ffi. So we are naturally afraid of any potential threading issues and want to be sure. Should it be safe to start separate MoorIsolate in BG and FG? Thanks. |
That could be problematic with the migration issue if the BG and FG create the database at roughly the same time. Apart from that, I don't see any potential threading issues ( |
Thanks for reply. Closing as it looks like it is working setup after some time |
I am developing flutter application (at the time just for Android, but with iOS support planned for later). Application operates in two ways:
Since we need to use Database in "thread-safe" manner we are trying to use Moor database framework, with moor_ffi interface to talk to Sqlite server.
Moor claims to achieve it's "thread-safety" by spawning the third Isolate (MoorIsolate). This isolate is the only one that talks to the database. Queries executed in BG and FG are sent to this isolate using SendPort/ReceivePort, executed and returned to caller Isolate.
However all Moor example suggest spawning MoorIsolate from FG isolate. Which draws my attention to following concerns.
The text was updated successfully, but these errors were encountered: