mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-15 01:52:45 +00:00
exclude fields and add a time limit
This commit is contained in:
@@ -10,40 +10,28 @@ const archive = {
|
|||||||
const limit = 2000;
|
const limit = 2000;
|
||||||
const brews = await HomebrewModel.find({
|
const brews = await HomebrewModel.find({
|
||||||
title: { $regex: req.params.query, $options: 'i' },
|
title: { $regex: req.params.query, $options: 'i' },
|
||||||
|
editId:0,
|
||||||
|
googleId:0,
|
||||||
|
text:0,
|
||||||
|
textBin:0,
|
||||||
published: true
|
published: true
|
||||||
})
|
})
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
.maxTimeMS(10000)
|
||||||
.exec();
|
.exec();
|
||||||
|
|
||||||
const simplifiedBrews = brews.map(brew => ({
|
if (!brews || brews.length === 0) {
|
||||||
title : brew.title,
|
|
||||||
description : brew.description,
|
|
||||||
authors : brew.authors,
|
|
||||||
tags : brew.tags,
|
|
||||||
pageCount : brew.pageCount,
|
|
||||||
systems : brew.systems,
|
|
||||||
renderer : brew.renderer,
|
|
||||||
thumbnail : brew.thumbnail,
|
|
||||||
createdAt : brew.createdAt,
|
|
||||||
updatedAt : brew.updatedAt,
|
|
||||||
lastViewed : brew.lastViewed,
|
|
||||||
views : brew.views,
|
|
||||||
shareId : brew.shareId,
|
|
||||||
googleId : brew.googleId
|
|
||||||
}))
|
|
||||||
|
|
||||||
if (!simplifiedBrews || simplifiedBrews.length === 0) {
|
|
||||||
// No published documents found with the given title
|
// No published documents found with the given title
|
||||||
return res.status(404).json({ error: 'Published documents not found' });
|
return res.status(404).json({ error: 'Published documents not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
let message = '';
|
let message = '';
|
||||||
if (simplifiedBrews.length === limit) {
|
if (brews.length === limit) {
|
||||||
// If the limit has been reached, include a message in the response
|
// If the limit has been reached, include a message in the response
|
||||||
message = `You've reached the limit of ${limit} documents, you can try being more specific in your search.`;
|
message = `You've reached the limit of ${limit} documents, you can try being more specific in your search.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.json({ simplifiedBrews, message });
|
return res.json({ brews, message });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return res.status(500).json({ error: 'Internal Server Error' });
|
return res.status(500).json({ error: 'Internal Server Error' });
|
||||||
|
|||||||
Reference in New Issue
Block a user