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

Meta PR: Implement offline support through CozyPouchLink #1507

Open
wants to merge 79 commits into
base: master
Choose a base branch
from

Conversation

Ldoppea
Copy link
Member

@Ldoppea Ldoppea commented Jul 26, 2024

Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Jul 30, 2024
We want the Flagship app to work when offline

To make this possible we configure cozy-client with CozyPouchLink which
role will be to synchronize necessary doctypes into a local PouchDB and
serve them from it instead of from the cozy-stack when the device is
offline

For now the list of synchronized doctypes is hardcoded but in the
future we expect to implement a dynamic list based on cozy-apps'
manifests

Related PR: cozy/cozy-client#1507
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Jul 30, 2024
In previous commit we configured cozy-client to use CozyPouchLink for
its queries

This commit also adds StackLink as the first Link so by default it will
do its queries through the remote cozy-stack

CozyClient has been modified to handle offline mode and redirect to the
next link when it is detected

Related PR: cozy/cozy-client#1507
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Jul 30, 2024
This plugin is required by cozy-client to process `find` queries

Related PR: cozy/cozy-client#1507
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Aug 26, 2024
We want the Flagship app to work when offline

To make this possible we configure cozy-client with CozyPouchLink which
role will be to synchronize necessary doctypes into a local PouchDB and
serve them from it instead of from the cozy-stack when the device is
offline

For now the list of synchronized doctypes is hardcoded but in the
future we expect to implement a dynamic list based on cozy-apps'
manifests

Related PR: cozy/cozy-client#1507
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Aug 26, 2024
In previous commit we configured cozy-client to use CozyPouchLink for
its queries

This commit also adds StackLink as the first Link so by default it will
do its queries through the remote cozy-stack

CozyClient has been modified to handle offline mode and redirect to the
next link when it is detected

Related PR: cozy/cozy-client#1507
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Aug 26, 2024
This plugin is required by cozy-client to process `find` queries

Related PR: cozy/cozy-client#1507
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Aug 26, 2024
We want the Flagship app to work when offline

To make this possible we configure cozy-client with CozyPouchLink which
role will be to synchronize necessary doctypes into a local PouchDB and
serve them from it instead of from the cozy-stack when the device is
offline

For now the list of synchronized doctypes is hardcoded but in the
future we expect to implement a dynamic list based on cozy-apps'
manifests

Related PR: cozy/cozy-client#1507
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Aug 26, 2024
In previous commit we configured cozy-client to use CozyPouchLink for
its queries

This commit also adds StackLink as the first Link so by default it will
do its queries through the remote cozy-stack

CozyClient has been modified to handle offline mode and redirect to the
next link when it is detected

Related PR: cozy/cozy-client#1507
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Aug 26, 2024
This plugin is required by cozy-client to process `find` queries

Related PR: cozy/cozy-client#1507
Ldoppea added a commit to cozy/mespapiers that referenced this pull request Aug 26, 2024
We want mespapiers to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/mespapiers that referenced this pull request Aug 27, 2024
We want mespapiers to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
packages/cozy-pouch-link/src/remote.spec.js Dismissed Show dismissed Hide dismissed
packages/cozy-pouch-link/src/remote.spec.js Dismissed Show dismissed Hide dismissed
Ldoppea added a commit to cozy/mespapiers that referenced this pull request Sep 13, 2024
We want mespapiers to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/mespapiers that referenced this pull request Sep 13, 2024
We want mespapiers to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/cozy-home that referenced this pull request Sep 16, 2024
We want cozy-home to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
Ldoppea added a commit to cozy/cozy-home that referenced this pull request Sep 19, 2024
We want cozy-home to be compatible with the new Flagship app's Offline
mode

When hosted in a Flagship app's WebView we now want to use FlagshipLink
instead of StackLink in cozy-client

This link will allow to redirect all queries to the Flagship app that
will handle data access when offline but also when online

Related PR: cozy/cozy-client#1507
Related PR: cozy/cozy-flagship-app#1239
When calling `yarn types` all cozy-client's types are generated inside
of the `cozy-client/types` folder

However, there is no mechanism to remove types when their corresponding
class is deleted

To fix this, we want to clean the types folder before regenerating
types so we ensure no fantom type would persist
For the Flagship app offline feature, we want to make some files
available offline

To make this possible, we want the cozy-apps to download files as usual
except when they are hosted in the FlagshipApp

In that scenario, we want the cozy-app to call the new `downloadFile`
intent

Also to ease future compatibility, we want to implement a new method
hosted in the `file` model instead of in the collection as before

So in order to handle offline files, the cozy-app will now need to call
`downloadFile()` method from `models/file`
In order to prevent implementation errors, we want to check that
storageEngine implements the correct methods

This replies to #1483 (comment)
We want to extract this code logic into its own method in order to ease
readability and testing

Also we refactored the code to make it easier to read

This replies to #1506 (comment)
This commit is a copy of #1517 applied to CozyPouchLink

When specifying fields in a query, e.g.
`Q('io.cozy.todos').where({done: true}).select(['date'])`, the revision
was missing if not explicitly given. This is now problematic because we
rely on the revision existence to identify "virtual" documents, i.e. not
persisted in CouchDB, that never have any revision.
See #1486 for more insights.
With CouchDB, it is possible to make a mango query on an index without
having any predicate on an sorted field in the selector

It is not possible with PouchDB that requires to have any sorted
fields to be in the selector

We automatically handle that to avoid breaking existing queries
This guard has been added to handle documents with no `meta.rev` but
since we added a check on `_rev` (in addition to `meta.rev`) to trigger
the persistence, then we don't need this guard anymore

This replies to #1486 (comment)

Related commit: b797eb3
Related commit: 62290ed
Previous implementation was from a misunderstanding of CozyPouchLink
mechanisms

As we don't need to specify warmup queries in CozyPouchLink
instanciation, we don't need the `ignoreWarmup` as we would result to
the same behavior of having no warmup queries

Warmup queries concept is meant to be removed into the future as we
won't be able to use them when offline and the scenario that needed
them (cozy-banks and cozy-drive apps) does not exist anymore

This replies to #1506 (comment)

Related commit: bb43ae9
Those doc's attributes are specific to the JSON API and should not be
inserted into the Pouch database

This implies that we will have a difference on documents regarding if
they are served through the cozy-stack or through a local PouchDB, the
first one may include those fields in their result, but not the second
one

So from now we should avoid, as much as possible, to relies on the
`attributes` member to prevent bugs on Offline mode. Multiple commits to
fix usages of `attributes` in cozy-client will be done after this one

Usage of `attributes` and `meta` members on cozy-app will also have to
be fixed. This will be a requirement to implement Offline mode on
cozy-apps

This replies to #1486 (comment)
By doing so we add unnecessary values to the capabilities object that
will now contain more data than just `.attributes`

As those are supernumerary values we consider that this is not
problematic, but we may want to find a cleaner solution in the future
Calls of `isInstalled` and all related methods have been checked and
`apps` parameter is always a result of `client.query()` so we know that
`.slug` can be used in replacement of `.attributes.slug`
Calls of those methods have been checked and `instanceInfo` parameter
is always a result of `useInstanceInfo` so we know that `.attributes`
can be omited
For some reason the Pouch engine would ignore any partialFilter if it
is not included in the selector

This may be the same reason we had to do this fix:
7c69838#diff-41848dd46551544674c134f359a5d7cddea46dd1e47c21da6814e1d1d585173dR482-R489
Previous implementation would not be backward compatible with older
Flagship app versions

By checking for method availability, we ensure the code is called only
on the correct Flagship app versions, otherwise the old process is
called

Related PR: #1518
In previous implementation we did not await for the
`persistVirtualDocuments()` result before completing the request

This was done because the persistance was not mandatory for the
request's result and doing it in parallel would be a good way to
optimize timings

But in some recent experiments we found a scenario where we would
benefit from the `await` in order to some external code until the data
is actually persisted

Related PR: #1486
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