Skip to content

Commit

Permalink
feat(search): improve search by querying fewer data
Browse files Browse the repository at this point in the history
Selector is mandatory when using .select or .partialIndex
cozy/cozy-client#1216
  • Loading branch information
trollepierre committed Aug 8, 2022
1 parent 6d07b39 commit 29d6c80
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## ✨ Features

* Improve speed of search suggestion by querying fewer data
* Update cozy-stack-client and cozy-pouch-link to sync with cozy-client version
* Update cozy-ui
- Modify Viewers to handle [68.0.0 BC](https://github.com/cozy/cozy-ui/releases/tag/v68.0.0)
Expand All @@ -12,7 +13,7 @@

* Improve cozy-bar implementation to fix UI bugs in Amirale
* Fix navigation through mobile Flagship on Note creation and opening
* Remove unused contacts permissions on Photos
* Remove unused contacts permissions on Photos

## 🔧 Tech

Expand Down
38 changes: 28 additions & 10 deletions src/drive/web/modules/services/components/SuggestionProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* global cozy */
import React from 'react'
import FuzzyPathSearch from '../FuzzyPathSearch'
import { withClient } from 'cozy-client'
import { withClient, Q } from 'cozy-client'

import { DOCTYPE_FILES } from 'drive/lib/doctypes'
import { TYPE_DIRECTORY, makeNormalizedFile } from './helpers'
import { getIconUrl } from './iconContext'
import { TRASH_DIR_ID } from 'drive/constants/config'

class SuggestionProvider extends React.Component {
componentDidMount() {
Expand Down Expand Up @@ -46,21 +48,37 @@ class SuggestionProvider extends React.Component {
)
}

// fetches pretty much all the files and preloads FuzzyPathSearch
// fetches pretty much all the files not trashed and preloads FuzzyPathSearch
async indexFiles() {
const { client } = this.props
// TODO: fix me
// eslint-disable-next-line no-async-promise-executor
return new Promise(async resolve => {
const resp = await cozy.client.fetchJSON(
'GET',
`/data/io.cozy.files/_all_docs?include_docs=true`
const files = await client.queryAll(
Q(DOCTYPE_FILES)
.partialIndex({
_id: {
$ne: TRASH_DIR_ID
},
trashed: {
$or: [
{
$exists: false
},
{
$eq: false
}
]
}
})
.select(['_id', 'trashed', 'dir_id', 'name', 'path'])
.where({
_id: {
$gt: null
}
})
.limitBy(1000)
)
const files = resp.rows
// TODO: fix me
// eslint-disable-next-line no-prototype-builtins
.filter(row => !row.doc.hasOwnProperty('views'))
.map(row => ({ id: row.id, ...row.doc }))

const folders = files.filter(file => file.type === TYPE_DIRECTORY)

Expand Down

0 comments on commit 29d6c80

Please sign in to comment.