Skip to content

Commit

Permalink
Added byVersion to status
Browse files Browse the repository at this point in the history
  • Loading branch information
macterra committed Dec 19, 2024
1 parent f189bd6 commit 666850e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/gatekeeper/src/gatekeeper-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ export async function checkDIDs(options = {}) {

const total = dids.length;
let n = 0;
let confirmed = 0;
let ephemeral = 0;
let invalid = 0;
const byRegistry = {};
const byVersion = {};

for (const did of dids) {
n += 1;
Expand All @@ -137,16 +139,19 @@ export async function checkDIDs(options = {}) {
console.log(`resolved ${n}/${total} ${did} OK`);
}

if (doc.didDocumentMetadata.confirmed) {
confirmed += 1;
}

if (doc.mdip.validUntil) {
ephemeral += 1;
}

if (byRegistry[doc.mdip.registry]) {
byRegistry[doc.mdip.registry] += 1;
}
else {
byRegistry[doc.mdip.registry] = 1;
}
const registry = doc.mdip.registry;
byRegistry[registry] = (byRegistry[registry] || 0) + 1;

const version = doc.didDocumentMetadata.version;
byVersion[version] = (byVersion[version] || 0) + 1;
}
catch (error) {
invalid += 1;
Expand All @@ -156,7 +161,7 @@ export async function checkDIDs(options = {}) {
}
}

return { total, ephemeral, invalid, byRegistry };
return { total, confirmed, ephemeral, invalid, byRegistry, byVersion };
}

export async function initRegistries(csvRegistries) {
Expand Down
13 changes: 13 additions & 0 deletions services/gatekeeper/server/src/gatekeeper-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ async function gcLoop() {
try {
const response = await gatekeeper.verifyDb();
console.log(`DID garbage collection: ${JSON.stringify(response)} waiting ${config.gcInterval} minutes...`);
await checkDids();
}
catch (error) {
console.error(`Error in DID garbage collection: ${error}`);
Expand Down Expand Up @@ -293,11 +294,23 @@ async function reportStatus() {

console.log(`DID Database (${config.db}):`);
console.log(` Total: ${status.dids.total}`);

console.log(` By registry:`);
const registries = Object.keys(status.dids.byRegistry).sort();
for (let registry of registries) {
console.log(` ${registry}: ${status.dids.byRegistry[registry]}`);
}

console.log(` By version:`);
let count = 0;
for (let version of [1, 2, 3, 4, 5]) {
const num = status.dids.byVersion[version];
console.log(` ${version}: ${num}`);
count += num;
}
console.log(` 6+: ${status.dids.total - count}`);

console.log(` Confirmed: ${status.dids.confirmed}`);
console.log(` Ephemeral: ${status.dids.ephemeral}`);
console.log(` Invalid: ${status.dids.invalid}`);

Expand Down
3 changes: 3 additions & 0 deletions tests/gatekeeper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2625,8 +2625,11 @@ describe('checkDIDs', () => {
const check = await gatekeeper.checkDIDs({ chatty: true });

expect(check.total).toBe(2);
expect(check.confirmed).toBe(2);
expect(check.ephemeral).toBe(1);
expect(check.invalid).toBe(0);
expect(check.byRegistry['local']).toBe(2);
expect(check.byVersion[1]).toBe(2);
});

it('should report invalid DIDs', async () => {
Expand Down

0 comments on commit 666850e

Please sign in to comment.