mirror of
https://github.com/logseq/logseq.git
synced 2026-05-20 19:02:23 +00:00
fix: lint and tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
(:require ["better-sqlite3" :as sqlite3]
|
||||
["fs" :as fs]
|
||||
["path" :as node-path]
|
||||
[clojure.string :as string]
|
||||
[datascript.core :as d]
|
||||
[logseq.db-sync.checksum :as sync-checksum]
|
||||
[logseq.db-sync.common :as common]
|
||||
@@ -54,11 +55,11 @@
|
||||
|
||||
(defn- normalize-sql
|
||||
[sql]
|
||||
(-> sql clojure.string/trim clojure.string/lower-case))
|
||||
(-> sql string/trim string/lower-case))
|
||||
|
||||
(defn- select-sql?
|
||||
[sql]
|
||||
(clojure.string/starts-with? (normalize-sql sql) "select"))
|
||||
(string/starts-with? (normalize-sql sql) "select"))
|
||||
|
||||
(defn- exec-with-args [^js stmt args]
|
||||
(.apply (.-run stmt) stmt (to-array args)))
|
||||
@@ -91,12 +92,6 @@
|
||||
[^js db]
|
||||
(.all (.prepare db "select t, tx, outliner_op from tx_log order by t asc")))
|
||||
|
||||
(defn- sync-meta-value
|
||||
[^js db key]
|
||||
(some-> (.all (.prepare db "select value from sync_meta where key = ?") key)
|
||||
first
|
||||
(aget "value")))
|
||||
|
||||
(defn- replay-find-first-mismatch
|
||||
[rows]
|
||||
(let [conn (d/create-conn db-schema/schema)]
|
||||
|
||||
@@ -71,16 +71,6 @@
|
||||
(:block/uuid ent)))))
|
||||
vec))
|
||||
|
||||
(defn- page-uuid
|
||||
[db]
|
||||
(some (fn [{:keys [e]}]
|
||||
(let [ent (d/entity db e)]
|
||||
(when (and (uuid? (:block/uuid ent))
|
||||
(not (ldb/built-in? ent))
|
||||
(string? (:block/name ent)))
|
||||
(:block/uuid ent))))
|
||||
(d/datoms db :avet :block/uuid)))
|
||||
|
||||
(defn- block-state
|
||||
[db]
|
||||
(->> (d/datoms db :avet :block/uuid)
|
||||
|
||||
@@ -113,30 +113,26 @@
|
||||
(is (= stale-checksum
|
||||
(storage/get-checksum sql)))))))))
|
||||
|
||||
(deftest listener-failure-can-leave-kvs-ahead-of-tx-log-test
|
||||
(testing "if listener append fails after store, kvs can persist while tx_log/t stay unchanged"
|
||||
(deftest stale-checksum-transact-keeps-kvs-and-tx-log-consistent-test
|
||||
(testing "stale checksum should not fail transact; kvs and tx_log/t should advance together"
|
||||
(with-memory-sql
|
||||
(fn [sql]
|
||||
(storage/init-schema! sql)
|
||||
(let [conn (storage/open-conn sql)
|
||||
stale-checksum "ffffffffffffffff"
|
||||
page-uuid (random-uuid)]
|
||||
;; Force append-tx-for-tx-report to throw on next non-empty tx.
|
||||
;; Use a stale checksum and ensure append path remains consistent.
|
||||
(storage/set-checksum! sql stale-checksum)
|
||||
(let [error (try
|
||||
(d/transact! conn [{:block/uuid page-uuid
|
||||
:block/name "repro-kvs-ahead-page"}])
|
||||
nil
|
||||
(catch :default e
|
||||
e))]
|
||||
(is (some? error))
|
||||
(is (string/includes? (or (ex-message error) (.-message error) "")
|
||||
"server checksum doesn't match"))
|
||||
;; Listener failed before append-tx!/next-t!, so tx_log/t/checksum metadata stay stale.
|
||||
(is (= 0 (storage/get-t sql)))
|
||||
(is (= [] (storage/fetch-tx-since sql 0)))
|
||||
(is (= stale-checksum (storage/get-checksum sql)))
|
||||
;; But kvs store can already be persisted; restoring a new conn sees the entity.
|
||||
(let [result (try
|
||||
(d/transact! conn [{:block/uuid page-uuid
|
||||
:block/name "repro-kvs-ahead-page"}])
|
||||
:ok
|
||||
(catch :default e
|
||||
e))]
|
||||
(is (= :ok result))
|
||||
(is (= 1 (storage/get-t sql)))
|
||||
(is (= 1 (count (storage/fetch-tx-since sql 0))))
|
||||
(is (not= stale-checksum (storage/get-checksum sql)))
|
||||
(let [restored-conn (storage/open-conn sql)]
|
||||
(is (= page-uuid
|
||||
(:block/uuid (d/entity @restored-conn [:block/uuid page-uuid])))))))))))
|
||||
|
||||
@@ -197,7 +197,7 @@
|
||||
{:tx (protocol/tx->transit [])
|
||||
:outliner-op :rebase})
|
||||
|
||||
(defn- tx-entry-appliable?
|
||||
(defn- tx-entry-applicable?
|
||||
[db {:keys [tx]}]
|
||||
(try
|
||||
(d/with db (protocol/transit->tx tx))
|
||||
@@ -205,9 +205,9 @@
|
||||
(catch :default _
|
||||
false)))
|
||||
|
||||
(defn- tx-entries-appliable?
|
||||
(defn- tx-entries-applicable?
|
||||
[db entries]
|
||||
(every? (partial tx-entry-appliable? db) entries))
|
||||
(every? (partial tx-entry-applicable? db) entries))
|
||||
|
||||
(defn- make-insert-command
|
||||
[rng db step]
|
||||
@@ -1001,7 +1001,7 @@
|
||||
;; undo
|
||||
(= op 1)
|
||||
(if-let [{:keys [forward inverse]} (peek undo-stack)]
|
||||
(let [entries (if (tx-entries-appliable? db inverse)
|
||||
(let [entries (if (tx-entries-applicable? db inverse)
|
||||
inverse
|
||||
[(no-op-rebase-entry)])
|
||||
response (apply-batch-with-t! self t-before entries)
|
||||
@@ -1022,7 +1022,7 @@
|
||||
;; redo
|
||||
(= op 2)
|
||||
(if-let [{:keys [forward inverse]} (peek redo-stack)]
|
||||
(let [entries (if (tx-entries-appliable? db forward)
|
||||
(let [entries (if (tx-entries-applicable? db forward)
|
||||
forward
|
||||
[(no-op-rebase-entry)])
|
||||
response (apply-batch-with-t! self t-before entries)
|
||||
@@ -1053,7 +1053,7 @@
|
||||
10 (make-random-indent-command rng db step)
|
||||
{:forward [(no-op-rebase-entry)]
|
||||
:undoable? false})
|
||||
entries (if (tx-entries-appliable? db (:forward command))
|
||||
entries (if (tx-entries-applicable? db (:forward command))
|
||||
(:forward command)
|
||||
[(no-op-rebase-entry)])
|
||||
response (apply-batch-with-t! self t-before entries)
|
||||
|
||||
2
deps/db/src/logseq/db/frontend/validate.cljs
vendored
2
deps/db/src/logseq/db/frontend/validate.cljs
vendored
@@ -49,7 +49,7 @@
|
||||
(defn validate-tx-report
|
||||
"Validates the datascript tx-report for entities that have changed. Returns
|
||||
boolean indicating if db is valid"
|
||||
[{:keys [db-before db-after tx-data tx-meta] :as tx-report} {:keys [closed-schema?]}]
|
||||
[{:keys [db-after tx-data tx-meta] :as tx-report} {:keys [closed-schema?]}]
|
||||
(binding [db-malli-schema/*skip-strict-url-validate?* true]
|
||||
(let [changed-ids (->> tx-data (keep :e) distinct)
|
||||
datoms (d/datoms db-after :eavt)
|
||||
|
||||
@@ -189,18 +189,18 @@
|
||||
|
||||
(defn- stable-block-uuid
|
||||
[db x]
|
||||
(let [ref (stable-entity-ref db x)]
|
||||
(let [entity-ref (stable-entity-ref db x)]
|
||||
(cond
|
||||
(uuid? ref)
|
||||
ref
|
||||
(uuid? entity-ref)
|
||||
entity-ref
|
||||
|
||||
(and (vector? ref)
|
||||
(= :block/uuid (first ref))
|
||||
(uuid? (second ref)))
|
||||
(second ref)
|
||||
(and (vector? entity-ref)
|
||||
(= :block/uuid (first entity-ref))
|
||||
(uuid? (second entity-ref)))
|
||||
(second entity-ref)
|
||||
|
||||
:else
|
||||
ref)))
|
||||
entity-ref)))
|
||||
|
||||
(defn- resolve-target-and-sibling
|
||||
[block]
|
||||
@@ -498,11 +498,11 @@
|
||||
[:recycle-delete-permanently [(stable-block-uuid db root-id)]])
|
||||
|
||||
:set-block-property
|
||||
(let [[block-eid property-id v] args]
|
||||
(let [property-id' (stable-entity-ref db property-id)]
|
||||
[:set-block-property [(stable-entity-ref db block-eid)
|
||||
property-id'
|
||||
(stable-property-value db property-id' v)]]))
|
||||
(let [[block-eid property-id v] args
|
||||
property-id' (stable-entity-ref db property-id)]
|
||||
[:set-block-property [(stable-entity-ref db block-eid)
|
||||
property-id'
|
||||
(stable-property-value db property-id' v)]])
|
||||
|
||||
:remove-block-property
|
||||
(let [[block-eid property-id] args]
|
||||
@@ -510,12 +510,12 @@
|
||||
(stable-entity-ref db property-id)]])
|
||||
|
||||
:batch-set-property
|
||||
(let [[block-ids property-id v opts] args]
|
||||
(let [property-id' (stable-entity-ref db property-id)]
|
||||
[:batch-set-property [(stable-id-coll db block-ids)
|
||||
property-id'
|
||||
(stable-property-value db property-id' v)
|
||||
opts]]))
|
||||
(let [[block-ids property-id v opts] args
|
||||
property-id' (stable-entity-ref db property-id)]
|
||||
[:batch-set-property [(stable-id-coll db block-ids)
|
||||
property-id'
|
||||
(stable-property-value db property-id' v)
|
||||
opts]])
|
||||
|
||||
:batch-remove-property
|
||||
(let [[block-ids property-id] args]
|
||||
@@ -523,18 +523,18 @@
|
||||
(stable-entity-ref db property-id)]])
|
||||
|
||||
:delete-property-value
|
||||
(let [[block-eid property-id property-value] args]
|
||||
(let [property-id' (stable-entity-ref db property-id)]
|
||||
[:delete-property-value [(stable-entity-ref db block-eid)
|
||||
property-id'
|
||||
(stable-property-value db property-id' property-value)]]))
|
||||
(let [[block-eid property-id property-value] args
|
||||
property-id' (stable-entity-ref db property-id)]
|
||||
[:delete-property-value [(stable-entity-ref db block-eid)
|
||||
property-id'
|
||||
(stable-property-value db property-id' property-value)]])
|
||||
|
||||
:batch-delete-property-value
|
||||
(let [[block-eids property-id property-value] args]
|
||||
(let [property-id' (stable-entity-ref db property-id)]
|
||||
[:batch-delete-property-value [(stable-id-coll db block-eids)
|
||||
property-id'
|
||||
(stable-property-value db property-id' property-value)]]))
|
||||
(let [[block-eids property-id property-value] args
|
||||
property-id' (stable-entity-ref db property-id)]
|
||||
[:batch-delete-property-value [(stable-id-coll db block-eids)
|
||||
property-id'
|
||||
(stable-property-value db property-id' property-value)]])
|
||||
|
||||
:create-property-text-block
|
||||
(let [[block-id property-id value opts] args]
|
||||
@@ -1306,10 +1306,6 @@
|
||||
|
||||
false)))
|
||||
|
||||
(defn- stale-numeric-id-in-op-stream?
|
||||
[db ops]
|
||||
(some #(stale-numeric-id-in-op? db %) ops))
|
||||
|
||||
(defn- assert-no-stale-numeric-ids!
|
||||
[db ops stage]
|
||||
(when-let [[idx op-entry] (some (fn [[idx op-entry]]
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
"sync-ios-release": "yarn clean && yarn release-mobile && rm -rf ./static/mobile/**/*.map && npx cap sync ios",
|
||||
"clean": "gulp clean",
|
||||
"test": "run-s cljs:test cljs:run-test",
|
||||
"test:node-adapter": "yarn --cwd deps/db-sync test:node-adapter",
|
||||
"report": "run-s cljs:report",
|
||||
"style:lint": "stylelint \"src/**/*.css\"",
|
||||
"gulp:watch": "gulp watch",
|
||||
|
||||
Reference in New Issue
Block a user