Skip to content

Conversation

paultranvan
Copy link
Contributor

When replicating files from CouchDB, we do not retrieve path, as it is
not persisted in database.
Therefore, we dynamically compute the path when a search returns files
results.
Note we do it at this moment rather than at replication time, because
this operation requires to query the parent directory, which can be done
directly in-memory through the store once the search index is built,
rather than an additional server query for each replicated file.

When replicating files from CouchDB, we do not retrieve path, as it is
not persisted in database.
Therefore, we dynamically compute the path when a search returns files
results.
Note we do it at this moment rather than at replication time, because
this operation requires to query the parent directory, which can be done
directly in-memory through the store once the search index is built,
rather than an additional server query for each replicated file.
Copy link

@cballevre cballevre left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@paultranvan paultranvan requested a review from Ldoppea October 28, 2024 12:41
@paultranvan paultranvan merged commit d956337 into main Oct 28, 2024
1 check passed
paultranvan added a commit that referenced this pull request Oct 30, 2024
Since #6,
we noticed a severe performance degradation when performing search.

We measured the following:
- Flexsearch search: <ms
- Query cozy-client store to get file paths: ~120ms for 60 files.
- Results normalization: ~3ms

We used to make multiple `getById` queries to get file path, each of
them taking few ms. So we tried to use a `getByIds` instead, and got
~70ms per query, which is better, but still slow.
Then, we tried the following:
```
  const allFiles = client.getCollectionFromState(FILES_DOCTYPE) as IOCozyFile[]
  const dirs = allFiles.filter(file => file.type === TYPE_DIRECTORY)
  return dirs.filter(dir => dirIds.includes(dir._id))
```

This takes 2ms.

We should eventually investigate why the store queries are so slow, but
for now let's use this trick.
paultranvan added a commit that referenced this pull request Oct 30, 2024
Since #6,
we noticed a severe performance degradation when performing search.

We measured the following:
- Flexsearch search: <ms
- Query cozy-client store to get file paths: ~120ms for 60 files.
- Results normalization: ~3ms

We used to make multiple `getById` queries to get file path, each of
them taking few ms. So we tried to use a `getByIds` instead, and got
~70ms per query, which is better, but still slow.
Then, we tried the following:
```
  const allFiles = client.getCollectionFromState(FILES_DOCTYPE) as IOCozyFile[]
  const dirs = allFiles.filter(file => file.type === TYPE_DIRECTORY)
  return dirs.filter(dir => dirIds.includes(dir._id))
```

This takes 2ms.

We should eventually investigate why the store queries are so slow, but
for now let's use this trick.
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.

3 participants