mirror of
https://github.com/zadam/trilium.git
synced 2025-11-12 16:25:51 +01:00
added entity changes check after sync check failure, fixed sync
This commit is contained in:
@@ -204,6 +204,11 @@ function queueSector(req) {
|
||||
entityChangesService.addEntityChangesForSector(entityName, sector);
|
||||
}
|
||||
|
||||
function checkEntityChanges() {
|
||||
const consistencyChecks = require("../../services/consistency_checks");
|
||||
consistencyChecks.runEntityChangesChecks();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
testSync,
|
||||
checkSync,
|
||||
@@ -215,5 +220,6 @@ module.exports = {
|
||||
update,
|
||||
getStats,
|
||||
syncFinished,
|
||||
queueSector
|
||||
queueSector,
|
||||
checkEntityChanges
|
||||
};
|
||||
|
||||
@@ -294,6 +294,7 @@ function register(app) {
|
||||
route(GET, '/api/sync/changed', [auth.checkApiAuth], syncApiRoute.getChanged, apiResultHandler);
|
||||
route(PUT, '/api/sync/update', [auth.checkApiAuth], syncApiRoute.update, apiResultHandler);
|
||||
route(POST, '/api/sync/finished', [auth.checkApiAuth], syncApiRoute.syncFinished, apiResultHandler);
|
||||
route(POST, '/api/sync/check-entity-changes', [auth.checkApiAuth], syncApiRoute.checkEntityChanges, apiResultHandler);
|
||||
route(POST, '/api/sync/queue-sector/:entityName/:sector', [auth.checkApiAuth], syncApiRoute.queueSector, apiResultHandler);
|
||||
route(GET, '/api/sync/stats', [], syncApiRoute.getStats, apiResultHandler);
|
||||
|
||||
|
||||
@@ -701,6 +701,11 @@ function runOnDemandChecks(autoFix) {
|
||||
consistencyChecks.runChecks();
|
||||
}
|
||||
|
||||
function runEntityChangesChecks() {
|
||||
const consistencyChecks = new ConsistencyChecks(true);
|
||||
consistencyChecks.findEntityChangeIssues();
|
||||
}
|
||||
|
||||
sqlInit.dbReady.then(() => {
|
||||
setInterval(cls.wrap(runPeriodicChecks), 60 * 60 * 1000);
|
||||
|
||||
@@ -709,5 +714,6 @@ sqlInit.dbReady.then(() => {
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
runOnDemandChecks
|
||||
runOnDemandChecks,
|
||||
runEntityChangesChecks
|
||||
};
|
||||
|
||||
@@ -149,7 +149,10 @@ async function pullChanges(syncContext) {
|
||||
|
||||
sql.transactional(() => {
|
||||
for (const {entityChange, entity} of entityChanges) {
|
||||
if (!sourceIdService.isLocalSourceId(entityChange.sourceId)) {
|
||||
// FIXME: temporary fix
|
||||
const existsAlready = !!sql.getValue("SELECT id FROM entity_changes WHERE entityName = ? AND entityId = ? AND utcDateChanged = ? AND hash = ?", [entityChange.entityName, entityChange.entityId, entityChange.utcDateChanged, entityChange.hash]);
|
||||
|
||||
if (!existsAlready && !sourceIdService.isLocalSourceId(entityChange.sourceId)) {
|
||||
if (!atLeastOnePullApplied) { // send only for first
|
||||
ws.syncPullInProgress();
|
||||
|
||||
@@ -249,6 +252,14 @@ async function checkContentHash(syncContext) {
|
||||
|
||||
const failedChecks = contentHashService.checkContentHashes(resp.entityHashes);
|
||||
|
||||
if (failedChecks.length > 0) {
|
||||
// before requeuing sectors make sure the entity changes are correct
|
||||
const consistencyChecks = require("./consistency_checks");
|
||||
consistencyChecks.runEntityChangesChecks();
|
||||
|
||||
await syncRequest(syncContext, 'POST', `/api/sync/check-entity-changes`);
|
||||
}
|
||||
|
||||
for (const {entityName, sector} of failedChecks) {
|
||||
entityChangesService.addEntityChangesForSector(entityName, sector);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user