Skip to content

Commit

Permalink
fix: sync remaining bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Feb 12, 2024
1 parent 64dacdf commit dd4c289
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/models/governance/governance.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ class Governance extends Model {
return;
}

const governanceData = await datalayer.getSubscribedStoreData(
GOVERNANCE_BODY_ID,
);
const governanceData =
await datalayer.getSubscribedStoreData(GOVERNANCE_BODY_ID);

// Check if there is v1, v2, v3 ..... and if not, then we assume this is a legacy governance table that isnt versioned
const shouldSyncLegacy = !Object.keys(governanceData).some((key) =>
Expand Down
10 changes: 5 additions & 5 deletions src/tasks/sync-registries.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,16 @@ const syncOrganizationAudit = async (organization) => {
currentGeneration = lastRootSaved;
}

const historyIndex = currentGeneration.generation;
const lastProcessedIndex = currentGeneration.generation;

if (historyIndex > rootHistory.length) {
if (lastProcessedIndex > rootHistory.length) {
logger.error(
`Could not find root history for ${organization.name} with timestamp ${currentGeneration.timestamp}, something is wrong and the sync for this organization will be paused until this is resolved.`,
);
}

const rootHistoryZeroBasedCount = rootHistory.length - 1;
const syncRemaining = rootHistoryZeroBasedCount - historyIndex;
const syncRemaining = rootHistoryZeroBasedCount - lastProcessedIndex;
const isSynced = syncRemaining === 0;

await Organization.update(
Expand All @@ -235,7 +235,7 @@ const syncOrganizationAudit = async (organization) => {
return;
}

const toBeProcessedIndex = historyIndex + 1;
const toBeProcessedIndex = lastProcessedIndex + 1;

// Organization not synced, sync it
logger.info(' ');
Expand All @@ -250,7 +250,7 @@ const syncOrganizationAudit = async (organization) => {
await new Promise((resolve) => setTimeout(resolve, 30000));
}

const root1 = _.get(rootHistory, `[${historyIndex}]`);
const root1 = _.get(rootHistory, `[${lastProcessedIndex}]`);
const root2 = _.get(rootHistory, `[${toBeProcessedIndex}]`);

logger.info(`ROOT 1 ${JSON.stringify(root1)}`);
Expand Down

0 comments on commit dd4c289

Please sign in to comment.