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 192a9e5 commit 64dacdf
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/tasks/sync-registries.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ const syncOrganizationAudit = async (organization) => {
);
}

const rootHistoryCount = rootHistory.length;
const syncRemaining = rootHistoryCount - historyIndex;
const isSynced = Boolean(rootHistory?.[historyIndex + 1]) === false;
const rootHistoryZeroBasedCount = rootHistory.length - 1;
const syncRemaining = rootHistoryZeroBasedCount - historyIndex;
const isSynced = syncRemaining === 0;

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

const toBeProcessedIndex = historyIndex + 1;

// Organization not synced, sync it
logger.info(' ');
logger.info(`Syncing ${organization.name} generation ${historyIndex}`);
logger.info(
`Syncing ${organization.name} generation ${toBeProcessedIndex}`,
);
logger.info(
`${organization.name} is ${syncRemaining} DataLayer generations away from being fully synced.`,
);
Expand All @@ -247,7 +251,7 @@ const syncOrganizationAudit = async (organization) => {
}

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

logger.info(`ROOT 1 ${JSON.stringify(root1)}`);
logger.info(`ROOT 2', ${JSON.stringify(root2)}`);
Expand Down Expand Up @@ -299,7 +303,7 @@ const syncOrganizationAudit = async (organization) => {

const updateTransaction = async (transaction, mirrorTransaction) => {
logger.info(
`Syncing ${organization.name} generation ${historyIndex + 1}`,
`Syncing ${organization.name} generation ${toBeProcessedIndex}`,
);
for (const diff of optimizedKvDiff) {
const key = decodeHex(diff.key);
Expand All @@ -313,7 +317,7 @@ const syncOrganizationAudit = async (organization) => {
table: modelKey,
change: decodeHex(diff.value),
onchainConfirmationTimeStamp: root2.timestamp,
generation: historyIndex + 1,
generation: toBeProcessedIndex,
comment: _.get(
tryParseJSON(
decodeHex(_.get(comment, '[0].value', encodeHex('{}'))),
Expand Down

0 comments on commit 64dacdf

Please sign in to comment.