Skip to content

Commit

Permalink
Save identity known heights from people chain, #960
Browse files Browse the repository at this point in the history
  • Loading branch information
wliyongfeng committed Sep 27, 2024
1 parent a2cf1df commit 4b9046e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
6 changes: 2 additions & 4 deletions backend/packages/identity-scan/src/scripts/known/identity.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const {
identity: { getIdentityTimelineCol },
} = require("@statescan/mongo");
const {
utils: { saveHeightsCommon },
} = require("@statescan/common");
const { saveHeights } = require("./save");

async function saveIdentityHeights() {
const timelineCol = await getIdentityTimelineCol();
await saveHeightsCommon(timelineCol);
await saveHeights(timelineCol);
}

module.exports = {
Expand Down
20 changes: 16 additions & 4 deletions backend/packages/identity-scan/src/scripts/known/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
require("dotenv").config();

const {
utils: { saveHeightsCommon },
} = require("@statescan/common");
const { saveIdentityHeights } = require("./identity");
const { saveRequestHeights } = require("./request");
const {
identity: { getRegistrarsTimelineCol },
} = require("@statescan/mongo");
const {
env: { currentChain },
mongo: {
known: { saveKnownHeights, getKnownHeightDb },
},
} = require("@osn/scan-common");
const { saveHeights } = require("./save");

const knownHeights = Object.freeze({
polkadot: [22572436],
kusama: [23780225],
});

(async () => {
await saveIdentityHeights();
await saveRequestHeights();
await saveHeightsCommon(await getRegistrarsTimelineCol());
await saveHeights(await getRegistrarsTimelineCol());

const known = knownHeights[currentChain()];
await saveKnownHeights(known);
process.exit(0);
})();
8 changes: 3 additions & 5 deletions backend/packages/identity-scan/src/scripts/known/request.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const {
identity: { getRequestCol, getRequestTimelineCol },
} = require("@statescan/mongo");
const {
utils: { saveHeightsCommon },
} = require("@statescan/common");
const { saveHeights } = require("./save");

async function saveRequestHeights() {
await saveHeightsCommon(await getRequestTimelineCol());
await saveHeightsCommon(await getRequestCol());
await saveHeights(await getRequestTimelineCol());
await saveHeights(await getRequestCol());
}

module.exports = {
Expand Down
6 changes: 5 additions & 1 deletion backend/packages/identity-scan/src/scripts/known/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function savePeopleChainHeights(heights = []) {
await bulk.execute();
}

async function saveHeightsCommon(col) {
async function saveHeights(col) {
const items = await col.find({}).toArray();
const heights = [];
const peopleChainHeights = [];
Expand Down Expand Up @@ -57,3 +57,7 @@ async function saveHeightsCommon(col) {
const uniquePeopleChainHeights = [...new Set(peopleChainHeights)];
await savePeopleChainHeights(uniquePeopleChainHeights);
}

module.exports = {
saveHeights,
};

0 comments on commit 4b9046e

Please sign in to comment.