Skip to content

Commit e9adc21

Browse files
committed
cache config
1 parent 634d258 commit e9adc21

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/utils/wrappa/postgres/query.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,20 @@ interface IAggregatedData {
4545

4646
type TimePeriod = "day" | "week" | "month";
4747

48+
let bridgeConfigCache: Record<string, string> = {};
49+
4850
const getBridgeID = async (bridgNetworkName: string, chain: string) => {
49-
return (
50-
await sql<IConfigID[]>`
51-
SELECT id FROM
52-
bridges.config
53-
WHERE
54-
bridge_name = ${bridgNetworkName} AND
55-
chain = ${chain};
56-
`
57-
)[0];
51+
if (bridgeConfigCache[`${bridgNetworkName}-${chain}`]) {
52+
return bridgeConfigCache[`${bridgNetworkName}-${chain}`];
53+
}
54+
const allConfigs = await sql`select * from bridges.config`;
55+
const idByChainAndName = allConfigs.reduce((acc, config) => {
56+
acc[`${config.bridge_name}-${config.chain}`] = config.id;
57+
return acc;
58+
}, {} as Record<string, string>);
59+
bridgeConfigCache = idByChainAndName;
60+
61+
return bridgeConfigCache[`${bridgNetworkName}-${chain}`];
5862
};
5963

6064
const getConfigsWithDestChain = async () => {

0 commit comments

Comments
 (0)