|
|
|
|
@ -2,6 +2,7 @@ const sql = require('./sql');
|
|
|
|
|
const source_id = require('./source_id');
|
|
|
|
|
const utils = require('./utils');
|
|
|
|
|
const messaging = require('./messaging');
|
|
|
|
|
const options = require('./options');
|
|
|
|
|
|
|
|
|
|
async function addNoteSync(noteId, sourceId) {
|
|
|
|
|
await addEntitySync("notes", noteId, sourceId)
|
|
|
|
|
@ -40,7 +41,7 @@ let startTime = utils.nowTimestamp();
|
|
|
|
|
let sentSyncId = [];
|
|
|
|
|
|
|
|
|
|
setInterval(async () => {
|
|
|
|
|
const syncs = await sql.getResults("SELECT * FROM sync WHERE sync_date >= ?", [startTime]);
|
|
|
|
|
const syncs = await sql.getResults("SELECT * FROM sync WHERE sync_date >= ? AND source_id != ?", [startTime, source_id.currentSourceId]);
|
|
|
|
|
startTime = utils.nowTimestamp();
|
|
|
|
|
|
|
|
|
|
const data = {};
|
|
|
|
|
@ -59,15 +60,16 @@ setInterval(async () => {
|
|
|
|
|
syncIds.push(sync.id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (syncIds.length > 0) {
|
|
|
|
|
messaging.send({
|
|
|
|
|
type: 'sync',
|
|
|
|
|
data: data
|
|
|
|
|
});
|
|
|
|
|
const lastSyncedPush = await sql.getSingleValue("SELECT opt_value FROM options WHERE opt_name = 'last_synced_push'");
|
|
|
|
|
|
|
|
|
|
for (const syncId of syncIds) {
|
|
|
|
|
sentSyncId.push(syncId);
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|