To prevent search lag when there are a large number of notes

This commit is contained in:
SiriusXT
2025-04-01 21:07:15 +08:00
parent a7799d32b0
commit adcb803caa
4 changed files with 15 additions and 13 deletions

View File

@@ -8,6 +8,7 @@ import cls from "../../services/cls.js";
import becca from "../../becca/becca.js";
import type { Request } from "express";
import ValidationError from "../../errors/validation_error.js";
import sql from "../../services/sql.js";
function getAutocomplete(req: Request) {
if (typeof req.query.query !== "string") {
@@ -79,6 +80,15 @@ function getRecentNotes(activeNoteId: string) {
});
}
// Get the total number of notes
function getNotesCount(req: Request) {
const notesCount = sql.getRow(
`SELECT COUNT(*) AS count FROM notes WHERE isDeleted = 0;`,
) as { count: number };
return notesCount.count;
}
export default {
getAutocomplete
getAutocomplete,
getNotesCount
};