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

refactor(mobile): split store into repo and service #16199

Merged
merged 4 commits into from
Feb 19, 2025

Conversation

shenlong-tanwen
Copy link
Member

@shenlong-tanwen shenlong-tanwen commented Feb 18, 2025

Changes made

The change is split into multiple PRs. This handles the following:

  • Refactored the App Store to use the repository pattern
  • All platform specific implementations will be inside the infrastructure folder

The following changes are to be made in the successive PRs:

  • Move the model and Store to be access from the domain
  • Removed the Store from using converters to and from DB which would make us depend on other repositories such as User repository to provide the current user and such and moved it to store only primitive values.
  • Moved the current user logic to a new Auth Service which will handle all the auth logic in the domain layer and also caches the current user that will be access from across the app.
  • Add test cases for the new service class

Copy link
Member

@danieldietzler danieldietzler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to lack of dart knowledge I can't really comment too much on the code; the structure seems to work well though. Also, take all my comments with a grain of salt, I don't know what's idiomatic in Dart.

@@ -0,0 +1,5 @@
abstract interface class IDatabaseRepository {
Future<T> nestTxn<T>(Future<T> Function() callback);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it typical to abbreviate function names in dart land? Usually I am against that, as it makes it harder to read for no benefit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it typical to abbreviate function names in dart land? Usually I am against that, as it makes it harder to read for no benefit.

Yes. But we can follow a similar convention to the server codebase in our mobile codebase as well. Will update all the methods to not use abbreviations

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The StoreKey enum is supposed to be defined in this file. I actually handled it in the next PR to minimise the number of places that needs updating

Comment on lines +8 to +11
final int? intValue;
final String? strValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, probably lack of dart knowledge, but (1) having the data type in the field name kind of sucks and (2) as I understand it either of them will always be undefined? If that's the case, wouldn't a generic make more sense? (or only storing the string and parsing it, idk)

Comment on lines 75 to 81
const (int) => entity.intValue,
const (String) => entity.strValue,
const (bool) => entity.intValue == 1,
const (DateTime) => entity.intValue == null
? null
: DateTime.fromMillisecondsSinceEpoch(entity.intValue!),
const (User) => await UserRepository(_db).get(entity.strValue!),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this kind of stuff is IMO just ugly, so I'd probably try to find a better data model for the entity as mentioned earlier.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but we are storing KV pairs inside a relational database which will always be ugly. We can instead store the entire setting as a single JSON string and parse it similar to the server SystemConfig

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer that, am interested for opinions of the others though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is okay to keep the implementation, as I think we will have a different way of storing KV in sqlite anyway

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is fair. We can revisit it then :)

if (version < targetVersion) {
_migrateTo(db, targetVersion);
final int version = StoreOld.getOldValue(StoreKey.version, 1)!;
if (version < 9) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version < _ktargetVersion? Isn't it the same as the if below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh the below if block is used to clear the tables and re-sync them whenever there is a change in the targetVersion. The new if block is to only perform the migration once when the user comes from a version lesser than 9

@alextran1502
Copy link
Contributor

@shenlong-tanwen
I tested the PR and it works well. Let's address the leftover comments and get this merged

@shenlong-tanwen
Copy link
Member Author

@shenlong-tanwen I tested the PR and it works well. Let's address the leftover comments and get this merged

All the pending comments should be resolved now.

@alextran1502 alextran1502 merged commit aeb3e0a into main Feb 19, 2025
38 checks passed
@alextran1502 alextran1502 deleted the refactor/store-domain branch February 19, 2025 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants