mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-30 20:41:33 +08:00 
			
		
		
		
	To prevent search lag when there are a large number of notes
This commit is contained in:
		
							parent
							
								
									a7799d32b0
								
							
						
					
					
						commit
						adcb803caa
					
				| @ -11,7 +11,8 @@ const SELECTED_NOTE_PATH_KEY = "data-note-path"; | ||||
| const SELECTED_EXTERNAL_LINK_KEY = "data-external-link"; | ||||
| 
 | ||||
| // To prevent search lag when there are a large number of notes, set a delay based on the number of notes to avoid jitter.
 | ||||
| const notesCount = await server.get<number>(`stats/notesCount`); | ||||
| const notesCount = await server.get<number>(`autocomplete/notesCount`); | ||||
| console.log(notesCount); | ||||
| let debounceTimeoutId: ReturnType<typeof setTimeout>; | ||||
| 
 | ||||
| function getSearchDelay(notesCount: number): number { | ||||
|  | ||||
| @ -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 | ||||
| }; | ||||
|  | ||||
| @ -48,16 +48,7 @@ function getSubtreeSize(req: Request) { | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| // 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 { | ||||
|     getNoteSize, | ||||
|     getSubtreeSize, | ||||
|     getNotesCount | ||||
|     getSubtreeSize | ||||
| }; | ||||
|  | ||||
| @ -273,6 +273,7 @@ function register(app: express.Application) { | ||||
|     route(PST, "/api/setup/sync-seed", [auth.checkAppNotInitialized], setupApiRoute.saveSyncSeed, apiResultHandler, false); | ||||
| 
 | ||||
|     apiRoute(GET, "/api/autocomplete", autocompleteApiRoute.getAutocomplete); | ||||
|     apiRoute(GET, "/api/autocomplete/notesCount", autocompleteApiRoute.getNotesCount); | ||||
|     apiRoute(GET, "/api/quick-search/:searchString", searchRoute.quickSearch); | ||||
|     apiRoute(GET, "/api/search-note/:noteId", searchRoute.searchFromNote); | ||||
|     apiRoute(PST, "/api/search-and-execute-note/:noteId", searchRoute.searchAndExecute); | ||||
| @ -361,7 +362,6 @@ function register(app: express.Application) { | ||||
|     apiRoute(GET, "/api/similar-notes/:noteId", similarNotesRoute.getSimilarNotes); | ||||
|     apiRoute(GET, "/api/backend-log", backendLogRoute.getBackendLog); | ||||
|     apiRoute(GET, "/api/stats/note-size/:noteId", statsRoute.getNoteSize); | ||||
|     apiRoute(GET, "/api/stats/notesCount", statsRoute.getNotesCount); | ||||
|     apiRoute(GET, "/api/stats/subtree-size/:noteId", statsRoute.getSubtreeSize); | ||||
|     apiRoute(PST, "/api/delete-notes-preview", notesApiRoute.getDeleteNotesPreview); | ||||
|     route(GET, "/api/fonts", [auth.checkApiAuthOrElectron], fontsRoute.getFontCss); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 SiriusXT
						SiriusXT