Skip to content

Commit

Permalink
⚡ Improve find query performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawidpol committed Nov 8, 2023
1 parent edc3555 commit b37631f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adminjs/mongoose",
"version": "3.0.3-reedsy-0.0.1",
"version": "3.0.3-reedsy-1.0.0",
"description": "Mongoose adapter for adminjs",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
12 changes: 12 additions & 0 deletions src/utils/convert-filter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import escape from 'escape-regexp'
import mongoose from 'mongoose'

const FIND_ONE_FIELDS = [
'_id',
'uuid',
] as const

/**
* Changes AdminJS's {@link Filter} to an object acceptible by a mongoose query.
*
Expand All @@ -11,6 +16,13 @@ export const convertFilter = (filter) => {
if (!filter) {
return {}
}

for (const field of FIND_ONE_FIELDS) {
if (field in filter && filter[field]) {
return { [field]: filter[field].value }
}
}

return filter.reduce((memo, filterProperty) => {
const { property, value } = filterProperty
switch (property.type()) {
Expand Down

0 comments on commit b37631f

Please sign in to comment.