mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	websocket reimplementation of status requests
This commit is contained in:
		| @@ -1,6 +1,7 @@ | ||||
| const sql = require('./sql'); | ||||
| const source_id = require('./source_id'); | ||||
| const utils = require('./utils'); | ||||
| const messaging = require('./messaging'); | ||||
|  | ||||
| async function addNoteSync(noteId, sourceId) { | ||||
|     await addEntitySync("notes", noteId, sourceId) | ||||
| @@ -35,6 +36,41 @@ async function addEntitySync(entityName, entityId, sourceId) { | ||||
|     }); | ||||
| } | ||||
|  | ||||
| let startTime = utils.nowTimestamp(); | ||||
| let sentSyncId = []; | ||||
|  | ||||
| setInterval(async () => { | ||||
|     const syncs = await sql.getResults("SELECT * FROM sync WHERE sync_date >= ?", [startTime]); | ||||
|     startTime = utils.nowTimestamp(); | ||||
|  | ||||
|     const data = {}; | ||||
|     const syncIds = []; | ||||
|  | ||||
|     for (const sync of syncs) { | ||||
|         if (sentSyncId.includes(sync.id)) { | ||||
|             continue; | ||||
|         } | ||||
|  | ||||
|         if (!data[sync.entity_name]) { | ||||
|             data[sync.entity_name] = []; | ||||
|         } | ||||
|  | ||||
|         data[sync.entity_name].push(sync.entity_id); | ||||
|         syncIds.push(sync.id); | ||||
|     } | ||||
|  | ||||
|     if (syncIds.length > 0) { | ||||
|         messaging.send({ | ||||
|             type: 'sync', | ||||
|             data: data | ||||
|         }); | ||||
|  | ||||
|         for (const syncId of syncIds) { | ||||
|             sentSyncId.push(syncId); | ||||
|         } | ||||
|     } | ||||
| }, 1000); | ||||
|  | ||||
| module.exports = { | ||||
|     addNoteSync, | ||||
|     addNoteTreeSync, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user