Skip to content

Commit cf63b82

Browse files
authored
Merge pull request #314 from CenterForDigitalHumanities/306-search-paging
`/search` optimization
2 parents 9e7b132 + 03f19ca commit cf63b82

6 files changed

Lines changed: 560 additions & 304 deletions

File tree

‎controllers/crud.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ const query = async function (req, res, next) {
8686
}
8787
const { limit, skip } = getPagination(req.query, { res })
8888
try {
89-
// One record past the page is read only to learn whether another page exists. It is never served.
90-
let matches = await db.find(props).sort({ _id: 1 }).limit(limit + 1).skip(skip).toArray()
89+
// Objects whose _id is not a string are bad data points, so they are not included.
90+
// One record past the page is read only to learn whether another page exists.
91+
let matches = await db.find({ $and: [props, { _id: { $type: "string" } }] })
92+
.sort({ _id: 1 }).limit(limit + 1).skip(skip).toArray()
9193
const hasNext = matches.length > limit
9294
matches = matches.slice(0, limit).map(o => idNegotiation(o))
9395
res.set(utils.configureLDHeadersFor(matches))

0 commit comments

Comments
 (0)