Skip to content

Conversation

@feyyazcigim
Copy link
Contributor

This pull request introduces a new "cache" subgraph and updates the application to use new cache-based queries and hooks for seasonal data throughout the explorer and stats pages. It also adds several new GraphQL query files specifically targeting the cache subgraph, and updates configuration and constants to support the new endpoints.

The most important changes are:

Cache Subgraph Integration:

  • Added a new "cache" subgraph endpoint to the subgraphs constant for all supported chains in src/constants/subgraph.ts.
  • Updated GraphQL code generation config in codegen.ts to generate types and operations for both the main and cache subgraphs, and to separate cache-related .graphql files.

GraphQL Query Additions for Cache:

  • Added several new .cache.graphql query files under src/queries/beanstalk/ and its subfolders, targeting cache data for advanced charts, seasonal tables, silo assets, field data, and active farmers. [1] [2] [3] [4] [5] [6] [7]

Migration to Cache-based Hooks in Seasonal Data:

  • Refactored explorer and stats pages (FarmerExplorer.tsx, FieldExplorer.tsx, SiloExplorer.tsx, SiloStats.tsx, Temperature.tsx) to use new *Cache hooks from seasonalDataHooks, ensuring all seasonal data is now fetched from the cache subgraph. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17]

These changes collectively improve data reliability and performance by centralizing seasonal data queries on a dedicated cache subgraph and ensure the frontend is aligned with the new backend structure.

@feyyazcigim feyyazcigim requested a review from burr-nim January 27, 2026 22:33
@netlify
Copy link

netlify bot commented Jan 27, 2026

Deploy Preview for pintomoney ready!

Name Link
🔨 Latest commit 55cbd6f
🔍 Latest deploy log https://app.netlify.com/projects/pintomoney/deploys/69793d4d57f0fa000864c921
😎 Deploy Preview https://deploy-preview-407.preview.pinto.money
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@feyyazcigim feyyazcigim changed the base branch from main to development January 27, 2026 22:34
}
})
.filter((v) => v !== undefined);
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stable function reference here. either pull this out, or in a useCallback()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but remove config.resultTimestamp() as a dependency

Comment on lines +83 to +86
const historicalQueryKey = [
`cache_historical_${keyName}`,
{ chainId, season: currentSeason, variables: historicalVars },
];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memoize this

Comment on lines +118 to +146
let historicalData: SeasonalChartData[] | undefined = historical.data;

// Fill sparse data gaps
if (sparseData && historical.data) {
let lastValue: SeasonalChartData;
historicalData = historical.data.flatMap((v, i) => {
let returnData: SeasonalChartData[] = [];
const gapSize = i === 0 ? 0 : v.season - lastValue.season;
if (gapSize > 1) {
returnData = Array.from({ length: gapSize - 1 }, (_, i) => ({
...lastValue,
season: lastValue.season + i + 1,
timestamp: new Date(lastValue.timestamp.getTime() + 3600 * 1000 * (i + 1)),
}));
}
returnData = [...returnData, v];
if (i === historical.data?.length - 1 && v.season < config.toSeason) {
const missingSize = config.toSeason - v.season;
const missingData: SeasonalChartData[] = Array.from({ length: missingSize }, (_, i) => ({
...v,
season: v.season + i + 1,
timestamp: new Date(v.timestamp.getTime() + 3600 * 1000 * (i + 1)),
}));
returnData = [...returnData, ...missingData];
}
lastValue = v;
return returnData;
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs stable reference. try to avoid 'let'

const lastFetchedTimestamp = queryInfo?.state?.dataUpdatedAt;
return config.convertResult(v, lastFetchedTimestamp ? new Date(lastFetchedTimestamp) : new Date());
});
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs stable reference

});
}

const currentQueryKey = [`cache_current_${keyName}`, { chainId, season: currentSeason, variables: currentVars }];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stable reference

export function useCacheWithSGFallback(cacheResult: UseSeasonalResult, sgResult: UseSeasonalResult): UseSeasonalResult {
// If cache is still loading, show loading state
if (cacheResult.isLoading) {
return { isLoading: true, isError: false, data: undefined };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pull this out to a stable ref

document: BeanstalkSeasonalFieldDocument,
buildWhere: (from, to) => buildSeasonRangeWhere(from, to, { field }),
resultKey: "fieldHourlySnapshots",
resultTimestamp: (entry) => new Date(Number(entry.createdAt) * 1000),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create stable reference these. Maybe pull this out into a utils folder?

parseSGResultTimestamp<T extends { createdAt: string }>({ createdAt }: T) => {...}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants