Skip to content

Commit

Permalink
improve log and update migration
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-aurele-besner committed Aug 8, 2024
1 parent 26391f6 commit 334b8ce
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 17 additions & 16 deletions indexers/staking-squid/src/utils/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const load = async (ctx: Ctx<Store>): Promise<Cache> => {
]);

console.log(
"Loaded in cache:",
"\x1b[32mLoaded in cache:\x1b[0m",
domains.length + " domains, ",
accounts.length + " accounts, ",
operators.length + " operators, ",
Expand Down Expand Up @@ -100,21 +100,22 @@ export const save = async (ctx: Ctx<Store>, cache: Cache) => {
// If the cache is not modified, skip saving
if (!cache.isModified) return;

let log = logEntry("domains", cache.domains);
log += logEntry("accounts", cache.accounts);
log += logEntry("operators", cache.operators);
log += logEntry("nominators", cache.nominators);

log += logEntry("deposits", cache.deposits);
log += logEntry("withdrawals", cache.withdrawals);
log += logEntry("bundles", cache.bundles);
log += logEntry("bundleAuthors", cache.bundleAuthors);
log += logEntry("operatorRewardedEvents", cache.operatorRewardedEvents);
log += logEntry("stats", cache.stats);
log += logEntry("statsPerDomain", cache.statsPerDomain);
log += logEntry("statsPerOperator", cache.statsPerOperator);

console.log("Saving in database:", log);
let logPerm = logEntry("domains", cache.domains);
logPerm += logEntry("accounts", cache.accounts);
logPerm += logEntry("operators", cache.operators);
logPerm += logEntry("nominators", cache.nominators);

let logTemp = logEntry("deposits", cache.deposits);
logTemp += logEntry("withdrawals", cache.withdrawals);
logTemp += logEntry("bundles", cache.bundles);
logTemp += logEntry("bundleAuthors", cache.bundleAuthors);
logTemp += logEntry("operatorRewardedEvents", cache.operatorRewardedEvents);
logTemp += logEntry("stats", cache.stats);
logTemp += logEntry("statsPerDomain", cache.statsPerDomain);
logTemp += logEntry("statsPerOperator", cache.statsPerOperator);

console.log("\x1b[34mSaving in database:\x1b[0m", logPerm);
console.log(" and ", logTemp, "\n");

await Promise.all(
Object.keys(cache).map((k) =>
Expand Down
13 changes: 8 additions & 5 deletions indexers/staking-squid/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ export const bundleUID = (
domainBlockHash: string
): string => `${domainId}-${domainBlockHash}`;

export const logBlock = (blocks: CtxBlock[]): void =>
console.log(
"Processing " + blocks.length + " blocks",
"From " + getBlockNumber(blocks[0]),
"to " + getBlockNumber(blocks[blocks.length - 1])
export const logBlock = (blocks: CtxBlock[]): void => {
const from = getBlockNumber(blocks[0]);
const to = getBlockNumber(blocks[blocks.length - 1]);
return console.log(
"\x1b[33mProcessing " + blocks.length + " blocks\x1b[0m",
"From " + from,
"to " + to + " (" + (to - from) + " blocks)"
);
};

0 comments on commit 334b8ce

Please sign in to comment.