sync only changes with isSynced = true

This commit is contained in:
zadam 2020-03-09 21:34:03 +01:00
parent da53c1eaa8
commit c6d912dcb7
4 changed files with 47 additions and 11 deletions

View File

@ -57,6 +57,7 @@
<index id="24" parent="6" name="sqlite_autoindex_api_tokens_1"> <index id="24" parent="6" name="sqlite_autoindex_api_tokens_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>apiTokenId</ColNames> <ColNames>apiTokenId</ColNames>
<ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<key id="25" parent="6"> <key id="25" parent="6">
@ -130,17 +131,21 @@
<index id="38" parent="7" name="sqlite_autoindex_attributes_1"> <index id="38" parent="7" name="sqlite_autoindex_attributes_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>attributeId</ColNames> <ColNames>attributeId</ColNames>
<ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<index id="39" parent="7" name="IDX_attributes_noteId_index"> <index id="39" parent="7" name="IDX_attributes_noteId_index">
<ColNames>noteId</ColNames> <ColNames>noteId</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<index id="40" parent="7" name="IDX_attributes_name_value"> <index id="40" parent="7" name="IDX_attributes_name_value">
<ColNames>name <ColNames>name
value</ColNames> value</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<index id="41" parent="7" name="IDX_attributes_value_index"> <index id="41" parent="7" name="IDX_attributes_value_index">
<ColNames>value</ColNames> <ColNames>value</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<key id="42" parent="7"> <key id="42" parent="7">
<ColNames>attributeId</ColNames> <ColNames>attributeId</ColNames>
@ -207,14 +212,17 @@ value</ColNames>
<index id="54" parent="8" name="sqlite_autoindex_branches_1"> <index id="54" parent="8" name="sqlite_autoindex_branches_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>branchId</ColNames> <ColNames>branchId</ColNames>
<ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<index id="55" parent="8" name="IDX_branches_noteId_parentNoteId"> <index id="55" parent="8" name="IDX_branches_noteId_parentNoteId">
<ColNames>noteId <ColNames>noteId
parentNoteId</ColNames> parentNoteId</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<index id="56" parent="8" name="IDX_branches_parentNoteId"> <index id="56" parent="8" name="IDX_branches_parentNoteId">
<ColNames>parentNoteId</ColNames> <ColNames>parentNoteId</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<key id="57" parent="8"> <key id="57" parent="8">
<ColNames>branchId</ColNames> <ColNames>branchId</ColNames>
@ -245,6 +253,7 @@ parentNoteId</ColNames>
<index id="62" parent="9" name="sqlite_autoindex_note_contents_1"> <index id="62" parent="9" name="sqlite_autoindex_note_contents_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>noteId</ColNames> <ColNames>noteId</ColNames>
<ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<key id="63" parent="9"> <key id="63" parent="9">
@ -275,6 +284,7 @@ parentNoteId</ColNames>
<index id="68" parent="10" name="sqlite_autoindex_note_revision_contents_1"> <index id="68" parent="10" name="sqlite_autoindex_note_revision_contents_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>noteRevisionId</ColNames> <ColNames>noteRevisionId</ColNames>
<ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<key id="69" parent="10"> <key id="69" parent="10">
@ -359,22 +369,28 @@ parentNoteId</ColNames>
<index id="84" parent="11" name="sqlite_autoindex_note_revisions_1"> <index id="84" parent="11" name="sqlite_autoindex_note_revisions_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>noteRevisionId</ColNames> <ColNames>noteRevisionId</ColNames>
<ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<index id="85" parent="11" name="IDX_note_revisions_noteId"> <index id="85" parent="11" name="IDX_note_revisions_noteId">
<ColNames>noteId</ColNames> <ColNames>noteId</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<index id="86" parent="11" name="IDX_note_revisions_utcDateLastEdited"> <index id="86" parent="11" name="IDX_note_revisions_utcDateLastEdited">
<ColNames>utcDateLastEdited</ColNames> <ColNames>utcDateLastEdited</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<index id="87" parent="11" name="IDX_note_revisions_utcDateCreated"> <index id="87" parent="11" name="IDX_note_revisions_utcDateCreated">
<ColNames>utcDateCreated</ColNames> <ColNames>utcDateCreated</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<index id="88" parent="11" name="IDX_note_revisions_dateLastEdited"> <index id="88" parent="11" name="IDX_note_revisions_dateLastEdited">
<ColNames>dateLastEdited</ColNames> <ColNames>dateLastEdited</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<index id="89" parent="11" name="IDX_note_revisions_dateCreated"> <index id="89" parent="11" name="IDX_note_revisions_dateCreated">
<ColNames>dateCreated</ColNames> <ColNames>dateCreated</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<key id="90" parent="11"> <key id="90" parent="11">
<ColNames>noteRevisionId</ColNames> <ColNames>noteRevisionId</ColNames>
@ -461,28 +477,36 @@ parentNoteId</ColNames>
<index id="105" parent="12" name="sqlite_autoindex_notes_1"> <index id="105" parent="12" name="sqlite_autoindex_notes_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>noteId</ColNames> <ColNames>noteId</ColNames>
<ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<index id="106" parent="12" name="IDX_notes_title"> <index id="106" parent="12" name="IDX_notes_title">
<ColNames>title</ColNames> <ColNames>title</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<index id="107" parent="12" name="IDX_notes_type"> <index id="107" parent="12" name="IDX_notes_type">
<ColNames>type</ColNames> <ColNames>type</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<index id="108" parent="12" name="IDX_notes_isDeleted"> <index id="108" parent="12" name="IDX_notes_isDeleted">
<ColNames>isDeleted</ColNames> <ColNames>isDeleted</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<index id="109" parent="12" name="IDX_notes_dateCreated"> <index id="109" parent="12" name="IDX_notes_dateCreated">
<ColNames>dateCreated</ColNames> <ColNames>dateCreated</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<index id="110" parent="12" name="IDX_notes_dateModified"> <index id="110" parent="12" name="IDX_notes_dateModified">
<ColNames>dateModified</ColNames> <ColNames>dateModified</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<index id="111" parent="12" name="IDX_notes_utcDateCreated"> <index id="111" parent="12" name="IDX_notes_utcDateCreated">
<ColNames>utcDateCreated</ColNames> <ColNames>utcDateCreated</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<index id="112" parent="12" name="IDX_notes_utcDateModified"> <index id="112" parent="12" name="IDX_notes_utcDateModified">
<ColNames>utcDateModified</ColNames> <ColNames>utcDateModified</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<key id="113" parent="12"> <key id="113" parent="12">
<ColNames>noteId</ColNames> <ColNames>noteId</ColNames>
@ -523,6 +547,7 @@ parentNoteId</ColNames>
<index id="120" parent="13" name="sqlite_autoindex_options_1"> <index id="120" parent="13" name="sqlite_autoindex_options_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>name</ColNames> <ColNames>name</ColNames>
<ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<key id="121" parent="13"> <key id="121" parent="13">
@ -558,6 +583,7 @@ parentNoteId</ColNames>
<index id="127" parent="14" name="sqlite_autoindex_recent_notes_1"> <index id="127" parent="14" name="sqlite_autoindex_recent_notes_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>noteId</ColNames> <ColNames>noteId</ColNames>
<ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<key id="128" parent="14"> <key id="128" parent="14">
@ -578,10 +604,12 @@ parentNoteId</ColNames>
<index id="131" parent="15" name="sqlite_autoindex_source_ids_1"> <index id="131" parent="15" name="sqlite_autoindex_source_ids_1">
<NameSurrogate>1</NameSurrogate> <NameSurrogate>1</NameSurrogate>
<ColNames>sourceId</ColNames> <ColNames>sourceId</ColNames>
<ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<index id="132" parent="15" name="IDX_source_ids_utcDateCreated"> <index id="132" parent="15" name="IDX_source_ids_utcDateCreated">
<ColNames>utcDateCreated</ColNames> <ColNames>utcDateCreated</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<key id="133" parent="15"> <key id="133" parent="15">
<ColNames>sourceId</ColNames> <ColNames>sourceId</ColNames>
@ -635,20 +663,28 @@ parentNoteId</ColNames>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<column id="145" parent="18" name="utcSyncDate"> <column id="145" parent="18" name="isSynced">
<Position>5</Position> <Position>5</Position>
<DataType>INTEGER|0s</DataType>
<NotNull>1</NotNull>
<DefaultExpression>0</DefaultExpression>
</column>
<column id="146" parent="18" name="utcSyncDate">
<Position>6</Position>
<DataType>TEXT|0s</DataType> <DataType>TEXT|0s</DataType>
<NotNull>1</NotNull> <NotNull>1</NotNull>
</column> </column>
<index id="146" parent="18" name="IDX_sync_entityName_entityId"> <index id="147" parent="18" name="IDX_sync_entityName_entityId">
<ColNames>entityName <ColNames>entityName
entityId</ColNames> entityId</ColNames>
<ColumnCollations></ColumnCollations>
<Unique>1</Unique> <Unique>1</Unique>
</index> </index>
<index id="147" parent="18" name="IDX_sync_utcSyncDate"> <index id="148" parent="18" name="IDX_sync_utcSyncDate">
<ColNames>utcSyncDate</ColNames> <ColNames>utcSyncDate</ColNames>
<ColumnCollations></ColumnCollations>
</index> </index>
<key id="148" parent="18"> <key id="149" parent="18">
<ColNames>id</ColNames> <ColNames>id</ColNames>
<Primary>1</Primary> <Primary>1</Primary>
</key> </key>

View File

@ -49,7 +49,7 @@ async function loginSync(req) {
return { return {
sourceId: sourceIdService.getCurrentSourceId(), sourceId: sourceIdService.getCurrentSourceId(),
maxSyncId: await sql.getValue("SELECT MAX(id) FROM sync") maxSyncId: await sql.getValue("SELECT MAX(id) FROM sync WHERE isSynced = 1")
}; };
} }

View File

@ -50,7 +50,7 @@ async function getStats() {
async function checkSync() { async function checkSync() {
return { return {
entityHashes: await contentHashService.getEntityHashes(), entityHashes: await contentHashService.getEntityHashes(),
maxSyncId: await sql.getValue('SELECT MAX(id) FROM sync') maxSyncId: await sql.getValue('SELECT MAX(id) FROM sync WHERE isSynced = 1')
}; };
} }
@ -116,11 +116,11 @@ async function forceNoteSync(req) {
async function getChanged(req) { async function getChanged(req) {
const lastSyncId = parseInt(req.query.lastSyncId); const lastSyncId = parseInt(req.query.lastSyncId);
const syncs = await sql.getRows("SELECT * FROM sync WHERE id > ? LIMIT 1000", [lastSyncId]); const syncs = await sql.getRows("SELECT * FROM sync WHERE isSynced = 1 AND id > ? LIMIT 1000", [lastSyncId]);
return { return {
syncs: await syncService.getSyncRecords(syncs), syncs: await syncService.getSyncRecords(syncs),
maxSyncId: await sql.getValue('SELECT MAX(id) FROM sync') maxSyncId: await sql.getValue('SELECT MAX(id) FROM sync WHERE isSynced = 1')
}; };
} }

View File

@ -176,7 +176,7 @@ async function pushSync(syncContext) {
let lastSyncedPush = await getLastSyncedPush(); let lastSyncedPush = await getLastSyncedPush();
while (true) { while (true) {
const syncs = await sql.getRows('SELECT * FROM sync WHERE id > ? LIMIT 1000', [lastSyncedPush]); const syncs = await sql.getRows('SELECT * FROM sync WHERE isSynced = 1 AND id > ? LIMIT 1000', [lastSyncedPush]);
if (syncs.length === 0) { if (syncs.length === 0) {
log.info("Nothing to push"); log.info("Nothing to push");
@ -236,7 +236,7 @@ async function checkContentHash(syncContext) {
return true; return true;
} }
const notPushedSyncs = await sql.getValue("SELECT EXISTS(SELECT 1 FROM sync WHERE id > ?)", [await getLastSyncedPush()]); const notPushedSyncs = await sql.getValue("SELECT EXISTS(SELECT 1 FROM sync WHERE isSynced = 1 AND id > ?)", [await getLastSyncedPush()]);
if (notPushedSyncs) { if (notPushedSyncs) {
log.info(`There's ${notPushedSyncs} outstanding pushes, skipping content check.`); log.info(`There's ${notPushedSyncs} outstanding pushes, skipping content check.`);
@ -353,7 +353,7 @@ async function updatePushStats() {
if (await syncOptions.isSyncSetup()) { if (await syncOptions.isSyncSetup()) {
const lastSyncedPush = await optionService.getOption('lastSyncedPush'); const lastSyncedPush = await optionService.getOption('lastSyncedPush');
stats.outstandingPushes = await sql.getValue("SELECT COUNT(1) FROM sync WHERE id > ?", [lastSyncedPush]); stats.outstandingPushes = await sql.getValue("SELECT COUNT(1) FROM sync WHERE isSynced = 1 AND id > ?", [lastSyncedPush]);
} }
} }