Merge remote-tracking branch 'origin/stable' into next

# Conflicts:
#	package-lock.json
#	package.json
This commit is contained in:
zadam 2021-05-15 22:45:11 +02:00
commit 9645a07f2f
7 changed files with 32 additions and 28 deletions

View File

@ -11,32 +11,32 @@ CREATE TABLE IF NOT EXISTS "mig_entity_changes" (
INSERT INTO mig_entity_changes (id, entityName, entityId, hash, sourceId, isSynced, utcDateChanged, isErased) INSERT INTO mig_entity_changes (id, entityName, entityId, hash, sourceId, isSynced, utcDateChanged, isErased)
SELECT id, entityName, entityId, '', sourceId, isSynced, utcChangedDate, 0 FROM entity_changes; SELECT id, entityName, entityId, '', sourceId, isSynced, utcChangedDate, 0 FROM entity_changes;
UPDATE mig_entity_changes SET isErased = (SELECT isErased FROM notes WHERE noteId = entityId) WHERE entityName = 'notes'; UPDATE mig_entity_changes SET isErased = COALESCE((SELECT isErased FROM notes WHERE noteId = entityId), 0) WHERE entityName = 'notes';
UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM notes WHERE noteId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'notes'; UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM notes WHERE noteId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'notes';
UPDATE mig_entity_changes SET isErased = (SELECT isErased FROM notes WHERE noteId = entityId) WHERE entityName = 'note_contents'; UPDATE mig_entity_changes SET isErased = COALESCE((SELECT isErased FROM notes WHERE noteId = entityId), 0) WHERE entityName = 'note_contents';
UPDATE mig_entity_changes SET isErased = ( UPDATE mig_entity_changes SET isErased = COALESCE((
SELECT isErased SELECT isErased
FROM attributes FROM attributes
JOIN notes USING(noteId) JOIN notes USING(noteId)
WHERE attributeId = entityId WHERE attributeId = entityId
) WHERE entityName = 'attributes'; ), 0) WHERE entityName = 'attributes';
UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM attributes WHERE attributeId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'attributes'; UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM attributes WHERE attributeId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'attributes';
UPDATE mig_entity_changes SET isErased = ( UPDATE mig_entity_changes SET isErased = COALESCE((
SELECT isErased SELECT isErased
FROM branches FROM branches
JOIN notes USING(noteId) JOIN notes USING(noteId)
WHERE branchId = entityId WHERE branchId = entityId
) WHERE entityName = 'branches'; ), 0) WHERE entityName = 'branches';
UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM branches WHERE branchId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'branches'; UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM branches WHERE branchId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'branches';
UPDATE mig_entity_changes SET isErased = ( UPDATE mig_entity_changes SET isErased = COALESCE((
SELECT isErased SELECT isErased
FROM note_revisions FROM note_revisions
WHERE noteRevisionId = entityId WHERE noteRevisionId = entityId
) WHERE entityName = 'note_revisions'; ), 0) WHERE entityName = 'note_revisions';
UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM note_revisions WHERE noteRevisionId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'note_revisions'; UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateModified FROM note_revisions WHERE noteRevisionId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'note_revisions';
UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateCreated FROM api_tokens WHERE apiTokenId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'api_tokens'; UPDATE mig_entity_changes SET utcDateChanged = COALESCE((SELECT utcDateCreated FROM api_tokens WHERE apiTokenId = entityId), '2020-12-14 14:07:05.165Z') WHERE entityName = 'api_tokens';

View File

@ -65,7 +65,7 @@ export default class LinkMap {
await froca.getNotes(Array.from(noteIds)); await froca.getNotes(Array.from(noteIds));
// pre-fetch the link titles, it's important to have hte construction afterwards synchronous // pre-fetch the link titles, it's important to have the construction afterwards synchronous
// since jsPlumb caculates width of the element // since jsPlumb caculates width of the element
const $linkTitles = {}; const $linkTitles = {};

View File

@ -3,7 +3,6 @@ import toastService from "../services/toast.js";
import ws from "../services/ws.js"; import ws from "../services/ws.js";
import options from "../services/options.js"; import options from "../services/options.js";
import syncService from "../services/sync.js"; import syncService from "../services/sync.js";
import appContext from "../services/app_context.js";
const TPL = ` const TPL = `
<div class="sync-status-widget"> <div class="sync-status-widget">
@ -108,7 +107,7 @@ export default class SyncStatusWidget extends BasicWidget {
showIcon(className) { showIcon(className) {
if (!options.get('syncServerHost')) { if (!options.get('syncServerHost')) {
this.$widget.hide(); this.toggleInt(false);
return; return;
} }
@ -127,29 +126,31 @@ export default class SyncStatusWidget extends BasicWidget {
}); });
this.syncState = 'in-progress'; this.syncState = 'in-progress';
this.allChangesPushed = false; this.lastSyncedPush = message.lastSyncedPush;
} }
else if (message.type === 'sync-push-in-progress') { else if (message.type === 'sync-push-in-progress') {
this.syncState = 'in-progress'; this.syncState = 'in-progress';
this.allChangesPushed = false; this.lastSyncedPush = message.lastSyncedPush;
} }
else if (message.type === 'sync-finished') { else if (message.type === 'sync-finished') {
// this gives user a chance to see the toast in case of fast sync finish // this gives user a chance to see the toast in case of fast sync finish
setTimeout(() => toastService.closePersistent('sync'), 1000); setTimeout(() => toastService.closePersistent('sync'), 1000);
this.syncState = 'connected'; this.syncState = 'connected';
this.lastSyncedPush = message.lastSyncedPush;
} }
else if (message.type === 'sync-failed') { else if (message.type === 'sync-failed') {
this.syncState = 'disconnected'; this.syncState = 'disconnected';
this.lastSyncedPush = message.lastSyncedPush;
} }
else if (message.type === 'frontend-update') { else if (message.type === 'frontend-update') {
const {lastSyncedPush} = message.data; this.lastSyncedPush = message.data.lastSyncedPush;
this.allChangesPushed = lastSyncedPush === ws.getMaxKnownEntityChangeSyncId();
} }
if (this.syncState === 'unknown') { this.allChangesPushed = this.lastSyncedPush === ws.getMaxKnownEntityChangeSyncId();
this.showIcon('unknown');
if (['unknown', 'in-progress'].includes(this.syncState)) {
this.showIcon(this.syncState);
} else { } else {
this.showIcon(this.syncState + '-' + (this.allChangesPushed ? 'no-changes' : 'with-changes')); this.showIcon(this.syncState + '-' + (this.allChangesPushed ? 'no-changes' : 'with-changes'));
} }

View File

@ -111,8 +111,6 @@ function forceNoteSync(req) {
entityChangesService.moveEntityChangeToTop('note_revision_contents', noteRevisionId); entityChangesService.moveEntityChangeToTop('note_revision_contents', noteRevisionId);
} }
entityChangesService.moveEntityChangeToTop('recent_changes', noteId);
log.info("Forcing note sync for " + noteId); log.info("Forcing note sync for " + noteId);
// not awaiting for the job to finish (will probably take a long time) // not awaiting for the job to finish (will probably take a long time)

View File

@ -48,9 +48,11 @@ function addNoteReorderingEntityChange(parentNoteId, sourceId) {
} }
function moveEntityChangeToTop(entityName, entityId) { function moveEntityChangeToTop(entityName, entityId) {
const [hash, isSynced] = sql.getRow(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [entityName, entityId]); const ec = sql.getRow(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [entityName, entityId]);
addEntityChange(entityName, entityId, hash, null, isSynced); const localEntityChange = insertEntityChange(entityName, entityId, ec.hash, ec.isErased, ec.utcDateChanged, ec.sourceId, ec.isSynced);
cls.addEntityChange(localEntityChange);
} }
function addEntityChangesForSector(entityName, sector) { function addEntityChangesForSector(entityName, sector) {

View File

@ -334,6 +334,7 @@ function getEntityChangesRecords(entityChanges) {
const entity = getEntityChangeRow(entityChange.entityName, entityChange.entityId); const entity = getEntityChangeRow(entityChange.entityName, entityChange.entityId);
if (entityChange.entityName === 'options' && !entity.isSynced) { if (entityChange.entityName === 'options' && !entity.isSynced) {
// if non-synced entities should count towards "lastSyncedPush"
records.push({entityChange}); records.push({entityChange});
continue; continue;
@ -358,7 +359,8 @@ function getLastSyncedPull() {
} }
function setLastSyncedPull(entityChangeId) { function setLastSyncedPull(entityChangeId) {
optionService.setOption('lastSyncedPull', entityChangeId); // this way we avoid updating entity_changes which otherwise means that we've never pushed all entity_changes
sql.execute("UPDATE options SET value = ? WHERE name = ?", [entityChangeId, 'lastSyncedPull']);
} }
function getLastSyncedPush() { function getLastSyncedPush() {
@ -372,7 +374,8 @@ function getLastSyncedPush() {
function setLastSyncedPush(entityChangeId) { function setLastSyncedPush(entityChangeId) {
ws.setLastSyncedPush(entityChangeId); ws.setLastSyncedPush(entityChangeId);
optionService.setOption('lastSyncedPush', entityChangeId); // this way we avoid updating entity_changes which otherwise means that we've never pushed all entity_changes
sql.execute("UPDATE options SET value = ? WHERE name = ?", [entityChangeId, 'lastSyncedPush']);
} }
function getMaxEntityChangeId() { function getMaxEntityChangeId() {

View File

@ -131,19 +131,19 @@ function sendTransactionEntityChangesToAllClients() {
} }
function syncPullInProgress() { function syncPullInProgress() {
sendMessageToAllClients({ type: 'sync-pull-in-progress' }); sendMessageToAllClients({ type: 'sync-pull-in-progress', lastSyncedPush });
} }
function syncPushInProgress() { function syncPushInProgress() {
sendMessageToAllClients({ type: 'sync-push-in-progress' }); sendMessageToAllClients({ type: 'sync-push-in-progress', lastSyncedPush });
} }
function syncFinished() { function syncFinished() {
sendMessageToAllClients({ type: 'sync-finished' }); sendMessageToAllClients({ type: 'sync-finished', lastSyncedPush });
} }
function syncFailed() { function syncFailed() {
sendMessageToAllClients({ type: 'sync-failed' }); sendMessageToAllClients({ type: 'sync-failed', lastSyncedPush });
} }
function setLastSyncedPush(entityChangeId) { function setLastSyncedPush(entityChangeId) {