Skip to content

Commit

Permalink
fix(SuggestionProvider): filter folder having path in trash
Browse files Browse the repository at this point in the history
Using PartialIndex will improve performance
  • Loading branch information
trollepierre committed Aug 8, 2022
1 parent 6673353 commit dc61669
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/drive/web/modules/services/components/SuggestionProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ class SuggestionProvider extends React.Component {
$eq: false
}
]
},
path: {
$or: [
{
$exists: false
},
{
$regex: '^(?!/.cozy_trash)'
}
]
}
})
.select(['_id', 'trashed', 'dir_id', 'name', 'path'])
Expand All @@ -79,12 +89,10 @@ class SuggestionProvider extends React.Component {

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

const notInTrash = file =>
!file.trashed && !/^\/\.cozy_trash/.test(file.path)
const notOrphans = file =>
folders.find(folder => folder._id === file.dir_id) !== undefined

const normalizedFilesPrevious = files.filter(notInTrash).filter(notOrphans)
const normalizedFilesPrevious = files.filter(notOrphans)

const normalizedFiles = await Promise.all(
normalizedFilesPrevious.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ describe('SuggestionProvider', () => {
limit: 1000,
partialFilter: {
_id: { $ne: 'io.cozy.files.trash-dir' },
trashed: { $or: [{ $exists: false }, { $eq: false }] }
trashed: { $or: [{ $exists: false }, { $eq: false }] },
path: { $or: [{ $exists: false }, { $regex: '^(?!/.cozy_trash)' }] }
},
selector: { _id: { $gt: null } }
})
Expand Down

0 comments on commit dc61669

Please sign in to comment.