mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 04:51:31 +08:00 
			
		
		
		
	show 0 changes to sync for instances without configured sync
This commit is contained in:
		
							parent
							
								
									8b5988e13c
								
							
						
					
					
						commit
						1231e02449
					
				
							
								
								
									
										2
									
								
								app.js
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								app.js
									
									
									
									
									
								
							| @ -10,6 +10,8 @@ const FileStore = require('session-file-store')(session); | |||||||
| const os = require('os'); | const os = require('os'); | ||||||
| const sessionSecret = require('./services/session_secret'); | const sessionSecret = require('./services/session_secret'); | ||||||
| 
 | 
 | ||||||
|  | require('./services/ping_job'); | ||||||
|  | 
 | ||||||
| const app = express(); | const app = express(); | ||||||
| 
 | 
 | ||||||
| // view engine setup
 | // view engine setup
 | ||||||
|  | |||||||
							
								
								
									
										44
									
								
								services/ping_job.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								services/ping_job.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,44 @@ | |||||||
|  | const sql = require('./sql'); | ||||||
|  | const source_id = require('./source_id'); | ||||||
|  | const utils = require('./utils'); | ||||||
|  | const messaging = require('./messaging'); | ||||||
|  | const options = require('./options'); | ||||||
|  | const sync = require('./sync'); | ||||||
|  | 
 | ||||||
|  | let startTime = utils.nowTimestamp(); | ||||||
|  | let sentSyncId = []; | ||||||
|  | 
 | ||||||
|  | setInterval(async () => { | ||||||
|  |     const syncs = await sql.getResults("SELECT * FROM sync WHERE sync_date >= ? AND source_id != ?", [startTime, source_id.currentSourceId]); | ||||||
|  |     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); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     const lastSyncedPush = await options.getOption('last_synced_push'); | ||||||
|  | 
 | ||||||
|  |     const changesToPushCount = await sql.getSingleValue("SELECT COUNT(*) FROM sync WHERE id > ?", [lastSyncedPush]); | ||||||
|  | 
 | ||||||
|  |     messaging.send({ | ||||||
|  |         type: 'sync', | ||||||
|  |         data: data, | ||||||
|  |         changesToPushCount: sync.isSyncSetup ? changesToPushCount : 0 | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     for (const syncId of syncIds) { | ||||||
|  |         sentSyncId.push(syncId); | ||||||
|  |     } | ||||||
|  | }, 1000); | ||||||
| @ -1,8 +1,6 @@ | |||||||
| const sql = require('./sql'); | const sql = require('./sql'); | ||||||
| const source_id = require('./source_id'); | const source_id = require('./source_id'); | ||||||
| const utils = require('./utils'); | const utils = require('./utils'); | ||||||
| const messaging = require('./messaging'); |  | ||||||
| const options = require('./options'); |  | ||||||
| 
 | 
 | ||||||
| async function addNoteSync(noteId, sourceId) { | async function addNoteSync(noteId, sourceId) { | ||||||
|     await addEntitySync("notes", noteId, sourceId) |     await addEntitySync("notes", noteId, sourceId) | ||||||
| @ -37,42 +35,6 @@ 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 >= ? AND source_id != ?", [startTime, source_id.currentSourceId]); |  | ||||||
|     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); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     const lastSyncedPush = await sql.getSingleValue("SELECT opt_value FROM options WHERE opt_name = 'last_synced_push'"); |  | ||||||
| 
 |  | ||||||
|     messaging.send({ |  | ||||||
|         type: 'sync', |  | ||||||
|         data: data, |  | ||||||
|         changesToPushCount: await sql.getSingleValue("SELECT COUNT(*) FROM sync WHERE id > ?", [lastSyncedPush]) |  | ||||||
|     }); |  | ||||||
| 
 |  | ||||||
|     for (const syncId of syncIds) { |  | ||||||
|         sentSyncId.push(syncId); |  | ||||||
|     } |  | ||||||
| }, 1000); |  | ||||||
| 
 |  | ||||||
| module.exports = { | module.exports = { | ||||||
|     addNoteSync, |     addNoteSync, | ||||||
|     addNoteTreeSync, |     addNoteTreeSync, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner