Avoid using statics and struct Singleton model for our database references

NEW
Unassigned

Status

()

Firefox for iOS
Sync
P3
normal
a year ago
11 months ago

People

(Reporter: sleroux, Unassigned)

Tracking

unspecified
Other
iOS

Firefox Tracking Flags

(fxios+)

Details

(Reporter)

Description

a year ago
Follow up for https://github.com/mozilla-mobile/firefox-ios/pull/2273

We currently use static variables to keep track of our DB open/closed states across (potentially) multiple profiles and use an older singleton model. We should revise how we maintain our references to these database models and try to not use statics if we can. We should also investigate options around memoizing disk access such as opening up our files reference for the DB.
To flesh this out a little:

The reason we use singleton DB references is to ensure that we don't accidentally open the DB twice. This might happen when triggering the share extension from inside Firefox itself. Multiple DB connections leads to occasional hard-to-fix bugs around concurrent writes.

It's conceptually neater to have the profile hold a reference to the DB, eliminating the singleton, but of course if we then instantiate the profile more than once, we'll open the DB more than once.

The fix for this is probably to do something a little like we do on Android: a static map from directory to profile, memoizing the profile itself. The share extensions and the main app would have a reference to the same profile instance.

The trouble there is that we'd have to get the closing lifecycle right again…
(Reporter)

Updated

11 months ago
tracking-fxios: ? → +
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.