This is an automated email from the ASF dual-hosted git repository.

guan404ming pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new dd9042279f [Web] Avoid redundant OPFS lookup on cache hit (#19791)
dd9042279f is described below

commit dd9042279f6e2e710068a5f344f934e3fdccfdf0
Author: Guan-Ming (Wesley) Chiu <[email protected]>
AuthorDate: Fri Jun 19 19:00:51 2026 +0800

    [Web] Avoid redundant OPFS lookup on cache hit (#19791)
---
 web/src/artifact_cache.ts | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/web/src/artifact_cache.ts b/web/src/artifact_cache.ts
index 35cc918f02..092f1fe3ee 100644
--- a/web/src/artifact_cache.ts
+++ b/web/src/artifact_cache.ts
@@ -617,22 +617,29 @@ export class ArtifactOPFSCache implements 
ArtifactCacheTemplate {
     storetype?: string,
     signal?: AbortSignal,
   ): Promise<any> {
-    // TODO: Avoid duplicate OPFS record validation by trying cache reads first
+    // Try the cache first to avoid a redundant OPFS lookup on a hit.
+    const cached = await this.readFromCache(url, storetype);
+    if (cached !== undefined) {
+      return cached;
+    }
     await this.addToCache(url, storetype, signal);
-    return this.readFromCache(url, storetype);
+    const fetched = await this.readFromCache(url, storetype);
+    if (fetched === undefined) {
+      throw new Error("ArtifactOPFSCache failed to fetch: " + url);
+    }
+    return fetched;
   }
 
-  private async readFromCache(url: string, storetype?: string): Promise<any> {
+  private async readFromCache(
+    url: string,
+    storetype?: string,
+  ): Promise<any> {
     if (storetype?.toLowerCase() === "arraybuffer") {
-      const cachedData = await this.store.readArrayBuffer(url);
-      if (cachedData === undefined) {
-        throw new Error("ArtifactOPFSCache failed to fetch: " + url);
-      }
-      return cachedData;
+      return this.store.readArrayBuffer(url);
     }
     const cachedResponse = await this.store.read(url);
     if (cachedResponse === undefined) {
-      throw new Error("ArtifactOPFSCache failed to fetch: " + url);
+      return undefined;
     }
     return this.responseToStoreType(cachedResponse, storetype);
   }

Reply via email to