Skip to content

Commit

Permalink
Improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJem committed Sep 14, 2023
1 parent 7a37681 commit dcd5b1a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
15 changes: 8 additions & 7 deletions apps/server/.wundergraph/operations/paginated/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ export default createOperation.query({
includeRecords: z.boolean({ description: "If true, includes the records used to calculate each metric." }).optional(),
}),
handler: async (ctx) => {
console.log(`Commencing paginated query for Metric`);
console.log(`Input: ${JSON.stringify(ctx.input)}`);
const FUNC = "paginated/metrics";
console.log(`${FUNC}: Commencing paginated query for Metric`);
console.log(`${FUNC}: Input: ${JSON.stringify(ctx.input)}`);
const finalStartDate: Date = new Date(ctx.input.startDate);
console.log(`finalStartDate: ${finalStartDate.toISOString()}`);
console.log(`${FUNC}: finalStartDate: ${finalStartDate.toISOString()}`);
if (isNaN(finalStartDate.getTime())) {
throw new Error(`startDate should be in the YYYY-MM-DD format.`);
}
Expand Down Expand Up @@ -53,7 +54,7 @@ export default createOperation.query({
byDateRecords.set(date, recordContainer);
});

console.log(`Processed ${protocolMetricsQueryResult.data.length} ProtocolMetric records.`);
console.log(`${FUNC}: Processed ${protocolMetricsQueryResult.data.length} ProtocolMetric records.`);
}

const tokenRecordsQueryResult = await ctx.operations.query({
Expand All @@ -79,7 +80,7 @@ export default createOperation.query({
byDateRecords.set(date, recordContainer);
});

console.log(`Processed ${tokenRecordsQueryResult.data.length} TokenRecord records.`);
console.log(`${FUNC}: Processed ${tokenRecordsQueryResult.data.length} TokenRecord records.`);
}

const tokenSuppliesQueryResult = await ctx.operations.query({
Expand All @@ -105,14 +106,14 @@ export default createOperation.query({
byDateRecords.set(date, recordContainer);
});

console.log(`Processed ${tokenSuppliesQueryResult.data.length} TokenSupply records.`);
console.log(`${FUNC}: Processed ${tokenSuppliesQueryResult.data.length} TokenSupply records.`);
}

// Convert into new Metric objects
byDateRecords.forEach((recordContainer, date) => {
const metricRecord: Metric | null = getMetricObject(recordContainer.tokenRecords, recordContainer.tokenSupplies, recordContainer.protocolMetrics, ctx.input.includeRecords);
if (!metricRecord) {
console.log(`Skipping date ${date} because it is missing data.`);
console.log(`${FUNC}: Skipping date ${date} because it is missing data.`);
return;
}

Expand Down
13 changes: 7 additions & 6 deletions apps/server/.wundergraph/operations/paginated/protocolMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export default createOperation.query({
dateOffset: z.number({ description: "The number of days to paginate by. Reduce the value if data is missing." }).optional(),
}),
handler: async (ctx) => {
console.log(`Commencing paginated query for ProtocolMetric`);
console.log(`Input: ${JSON.stringify(ctx.input)}`);
const FUNC = "paginated/protocolMetrics";
console.log(`${FUNC}: Commencing paginated query for ProtocolMetric`);
console.log(`${FUNC}: Input: ${JSON.stringify(ctx.input)}`);
const finalStartDate: Date = new Date(ctx.input.startDate);
console.log(`finalStartDate: ${finalStartDate.toISOString()}`);
console.log(`${FUNC}: finalStartDate: ${finalStartDate.toISOString()}`);
if (isNaN(finalStartDate.getTime())) {
throw new Error(`startDate should be in the YYYY-MM-DD format.`);
}
Expand All @@ -34,7 +35,7 @@ export default createOperation.query({
let currentEndDate: Date = getNextEndDate(null);

while (currentStartDate.getTime() >= finalStartDate.getTime()) {
console.log(`Querying for ${getISO8601DateString(currentStartDate)} to ${getISO8601DateString(currentEndDate)}`);
console.log(`${FUNC}: Querying for ${getISO8601DateString(currentStartDate)} to ${getISO8601DateString(currentEndDate)}`);
const queryResult = await ctx.operations.query({
operationName: "raw/internal/protocolMetrics",
input: {
Expand All @@ -56,12 +57,12 @@ export default createOperation.query({
// Ensures that a finalStartDate close to the current date (within the first page) is handled correctly
// There is probably a cleaner way to do this, but this works for now
if (currentStartDate == finalStartDate) {
console.log(`Reached final start date.`);
console.log(`${FUNC}: Reached final start date.`);
break;
}
}

console.log(`Returning ${combinedProtocolMetrics.length} records.`);
console.log(`${FUNC}: Returning ${combinedProtocolMetrics.length} records.`);
return sortRecordsDescending(combinedProtocolMetrics);
},
});
13 changes: 7 additions & 6 deletions apps/server/.wundergraph/operations/paginated/tokenRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ export default createOperation.query({
crossChainDataComplete: z.boolean({ description: "If true, returns data up to the most recent day in which all subgraphs have data." }).optional(),
}),
handler: async (ctx) => {
console.log(`Commencing paginated query for TokenRecord`);
console.log(`Input: ${JSON.stringify(ctx.input)}`);
const FUNC = "paginated/tokenRecords";
console.log(`${FUNC}: Commencing paginated query for TokenRecord`);
console.log(`${FUNC}: Input: ${JSON.stringify(ctx.input)}`);
const finalStartDate: Date = new Date(ctx.input.startDate);
console.log(`finalStartDate: ${finalStartDate.toISOString()}`);
console.log(`${FUNC}: finalStartDate: ${finalStartDate.toISOString()}`);
if (isNaN(finalStartDate.getTime())) {
throw new Error(`startDate should be in the YYYY-MM-DD format.`);
}
Expand All @@ -65,7 +66,7 @@ export default createOperation.query({
let hasProcessedFirstDate = false;

while (currentStartDate.getTime() >= finalStartDate.getTime()) {
console.log(`Querying for ${getISO8601DateString(currentStartDate)} to ${getISO8601DateString(currentEndDate)}`);
console.log(`${FUNC}: Querying for ${getISO8601DateString(currentStartDate)} to ${getISO8601DateString(currentEndDate)}`);
const queryResult = await ctx.operations.query({
operationName: "tokenRecords",
input: {
Expand All @@ -88,12 +89,12 @@ export default createOperation.query({
// Ensures that a finalStartDate close to the current date (within the first page) is handled correctly
// There is probably a cleaner way to do this, but this works for now
if (currentStartDate == finalStartDate) {
console.log(`Reached final start date.`);
console.log(`${FUNC}: Reached final start date.`);
break;
}
}

console.log(`Returning ${combinedTokenRecords.length} records.`);
console.log(`${FUNC}: Returning ${combinedTokenRecords.length} records.`);
return sortRecordsDescending(combinedTokenRecords);
},
});
13 changes: 7 additions & 6 deletions apps/server/.wundergraph/operations/paginated/tokenSupplies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ export default createOperation.query({
crossChainDataComplete: z.boolean({ description: "If true, returns data up to the most recent day in which all subgraphs have data." }).optional(),
}),
handler: async (ctx) => {
console.log(`Commencing paginated query for TokenSupply`);
console.log(`Input: ${JSON.stringify(ctx.input)}`);
const FUNC = "paginated/tokenSupplies";
console.log(`${FUNC}: Commencing paginated query for TokenSupply`);
console.log(`${FUNC}: Input: ${JSON.stringify(ctx.input)}`);
const finalStartDate: Date = new Date(ctx.input.startDate);
console.log(`finalStartDate: ${finalStartDate.toISOString()}`);
console.log(`${FUNC}: finalStartDate: ${finalStartDate.toISOString()}`);
if (isNaN(finalStartDate.getTime())) {
throw new Error(`startDate should be in the YYYY-MM-DD format.`);
}
Expand All @@ -69,7 +70,7 @@ export default createOperation.query({
let hasProcessedFirstDate = false;

while (currentStartDate.getTime() >= finalStartDate.getTime()) {
console.log(`Querying for ${getISO8601DateString(currentStartDate)} to ${getISO8601DateString(currentEndDate)}`);
console.log(`${FUNC}: Querying for ${getISO8601DateString(currentStartDate)} to ${getISO8601DateString(currentEndDate)}`);
const queryResult = await ctx.operations.query({
operationName: "tokenSupplies",
input: {
Expand All @@ -92,12 +93,12 @@ export default createOperation.query({
// Ensures that a finalStartDate close to the current date (within the first page) is handled correctly
// There is probably a cleaner way to do this, but this works for now
if (currentStartDate == finalStartDate) {
console.log(`Reached final start date.`);
console.log(`${FUNC}: Reached final start date.`);
break;
}
}

console.log(`Returning ${combinedTokenSupplies.length} records.`);
console.log(`${FUNC}: Returning ${combinedTokenSupplies.length} records.`);
return sortRecordsDescending(combinedTokenSupplies);
},
});

0 comments on commit dcd5b1a

Please sign in to comment.