diff --git a/AGENTS.md b/AGENTS.md index 4e5318c013..643bca2f80 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -37,3 +37,4 @@ - DB-sync protocol reference: `docs/agent-guide/db-sync/protocol.md`. - New properties should be added to `logseq.db.frontend.property/built-in-properties`. - Avoid creating new class or property unless you have to. +- Avoid shadow var, e.g. `bytes` should be named as `payload`. diff --git a/src/main/frontend/handler/db_based/sync.cljs b/src/main/frontend/handler/db_based/sync.cljs index 933466e72a..78250533d9 100644 --- a/src/main/frontend/handler/db_based/sync.cljs +++ b/src/main/frontend/handler/db_based/sync.cljs @@ -87,23 +87,23 @@ (throw (ex-info "incomplete framed buffer" {:buffer buffer :rows rows})))))) (defn- gzip-bytes? - [^js bytes] - (and (some? bytes) - (>= (.-byteLength bytes) 2) - (= 31 (aget bytes 0)) - (= 139 (aget bytes 1)))) + [^js payload] + (and (some? payload) + (>= (.-byteLength payload) 2) + (= 31 (aget payload 0)) + (= 139 (aget payload 1)))) (defn- bytes->stream - [^js bytes] + [^js payload] (js/ReadableStream. #js {:start (fn [controller] - (.enqueue controller bytes) + (.enqueue controller payload) (.close controller))})) (defn- stream bytes) + (p/let [stream (bytes->stream payload) decompressed (.pipeThrough stream (js/DecompressionStream. "gzip")) resp (js/Response. decompressed) buf (.arrayBuffer resp)] @@ -114,10 +114,10 @@ (defn- uint8 buf)] - (if (gzip-bytes? bytes) - (uint8 buf)] + (if (gzip-bytes? payload) + (