MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / getCachedGraph

Function getCachedGraph

website/src/pages/Explore.tsx:87–118  ·  view source on GitHub ↗
(ref: RepoRef)

Source from the content-addressed store, hash-verified

85};
86
87const getCachedGraph = async (ref: RepoRef): Promise<any | null> => {
88 try {
89 const db = await openDB();
90 const cacheKeys = [getCacheKey(ref), getLegacyCacheKey(ref)];
91 return new Promise((resolve, reject) => {
92 const transaction = db.transaction(STORE_NAME, "readonly");
93 const store = transaction.objectStore(STORE_NAME);
94 let pending = cacheKeys.length;
95 let found: any | null = null;
96
97 for (const key of cacheKeys) {
98 const request = store.get(key);
99 request.onerror = () => reject(request.error);
100 request.onsuccess = () => {
101 const result = request.result;
102 if (
103 !found &&
104 result &&
105 Date.now() - result.timestamp < 7 * 24 * 60 * 60 * 1000
106 ) {
107 found = result.graphData;
108 }
109 pending -= 1;
110 if (pending === 0) resolve(found);
111 };
112 }
113 });
114 } catch (e) {
115 console.error("Failed to read from IndexedDB", e);
116 return null;
117 }
118};
119
120const cacheGraph = async (ref: RepoRef, graphData: any): Promise<void> => {
121 try {

Callers 1

autoFetchAndIndexFunction · 0.85

Calls 6

getCacheKeyFunction · 0.90
getLegacyCacheKeyFunction · 0.90
openDBFunction · 0.85
resolveFunction · 0.85
errorMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected