Skip to content

WIP: Implement an async SqliteStorage class#37

Open
dcaliste wants to merge 4 commits into
sailfishos:masterfrom
dcaliste:cleanup
Open

WIP: Implement an async SqliteStorage class#37
dcaliste wants to merge 4 commits into
sailfishos:masterfrom
dcaliste:cleanup

Conversation

@dcaliste
Copy link
Copy Markdown
Contributor

@dcaliste dcaliste commented Dec 1, 2022

This is my latest attempt to create an async SqliteStorage backend. The purpose is to get an async access to the storage with the same ExtendedStorage API. I still need to use this new implementation in nemo-qml-plugin-calendar, so there should be still changes here and there. But I've created a new test set for this async implementation, trying to use all methods necessary for the QML plugin and they seem to pass.

It is based on the following:

  • the internal from SqliteFormat is now using real pointers on load, and the caller is responsible for taking ownership. In the sync case, a ::Ptr is immediately taking ownership. In the async case, the pointer is passed to the main thread and there, ownership is taken with a ::Ptr.
  • the sync and async SqliteStorage implementation are completely shared thanks to a new sqlitestorage_p.cpp file that is taking the old SqliteStorage::Private class.
  • the API of ExtendedStorage has been divided into two, the DirectStorage API and the rest. The latter got all the functions that are working on a calendar() populating it or taking changes to store them. The former got all the functions that work on the DB directly, either to read it or modify it. For backward compatibility, ExtendedStorage is inheriting DirectStorage, so the exposed API for ExtendedStorage actually doesn't changed. But this allow to separate the observer into something that is observing the effect on the calendar() and something that observe the effect on the DB. The former methods are called in the main thread while the latter methods are called in the working thread. For the sync case, this has no effect. But for the async case, this allow to run additional code on DB depending on action without passing back to the main thread.

As a bonus point, I've much reduced the virtual = 0 API of ExtendedStorage by introducing a polymorphic DBLoadOperation structure that is used internally instead of all the load*() methods.

@pvuorela , as mentioned, this is still WIP and does not require any immediate reviewing. It's more to make the proposition public so you can look at it and give feedback when it suits you.

ExtendedStorage methods have been splitted between methods
dealing with a proxy (the calendar for incidences and the
notebook list) and methods working directly on the database.
The latter have been moved into a new DirectStorageInterface
class.

The previous SqliteStorage::Private class has been moved out
in separated sqlitestorage_p.{cpp,h} files. And a new
AsyncSqliteStorage class has been created using the new
SqliteStorageImpl from a worker thread. Exchange between
the worker thread and the main thread are done via
signals and are non blocking for all methods using a
proxy. For direct methods, the call are blocking.
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

Successfully merging this pull request may close these issues.

1 participant