(ref: RepoRef)
| 85 | }; |
| 86 | |
| 87 | const 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 | |
| 120 | const cacheGraph = async (ref: RepoRef, graphData: any): Promise<void> => { |
| 121 | try { |
no test coverage detected