Skip to content

Commit

Permalink
Merge pull request #111 from jinaga/log-read
Browse files Browse the repository at this point in the history
Log the count of facts read on query
  • Loading branch information
michaellperry authored Jan 13, 2025
2 parents 12fbd25 + 72a3e59 commit b177583
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/jinaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ export class Jinaga {
});
await this.factManager.fetch(references, innerSpecification);
const projectedResults = await this.factManager.read(references, innerSpecification);
return extractResults(projectedResults, innerSpecification.projection);
const extracted = extractResults(projectedResults, innerSpecification.projection);
Trace.counter("facts_loaded", extracted.totalCount);
return extracted.results;
}

/**
Expand Down Expand Up @@ -294,14 +296,17 @@ export class Jinaga {

function extractResults(projectedResults: ProjectedResult[], projection: Projection) {
const results = [];
let totalCount = 0;
for (const projectedResult of projectedResults) {
let result = projectedResult.result;
if (projection.type === "composite") {
const obj: any = {};
for (const component of projection.components) {
const value = result[component.name];
if (component.type === "specification") {
obj[component.name] = extractResults(value, component.projection);
const { results: nestedResults, totalCount: nestedCount } = extractResults(value, component.projection);
obj[component.name] = nestedResults;
totalCount += nestedCount;
}
else {
obj[component.name] = value;
Expand All @@ -310,6 +315,7 @@ function extractResults(projectedResults: ProjectedResult[], projection: Project
result = obj;
}
results.push(result);
totalCount++;
}
return results;
return { results, totalCount };
}

0 comments on commit b177583

Please sign in to comment.