diff --git a/src/fluree/db/api/query.cljc b/src/fluree/db/api/query.cljc index 4151482e9..4df3ced6b 100644 --- a/src/fluree/db/api/query.cljc +++ b/src/fluree/db/api/query.cljc @@ -95,20 +95,22 @@ (defn t-flakes->json-ld [db compact cache fuel error-ch t-flakes] (go-try - (let [assert-flakes (not-empty (filter flake/op t-flakes)) - retract-flakes (not-empty (filter (complement flake/op) t-flakes)) + (let [{assert-flakes true + retract-flakes false} (group-by flake/op t-flakes) - s-asserts-ch (->> (sort-by flake/s assert-flakes) - (partition-by flake/s) - (async/to-chan!)) - s-retracts-ch (->> (sort-by flake/s retract-flakes) - (partition-by flake/s) - (async/to-chan!)) + s-flake-partitions (fn [flakes] + (->> flakes + (group-by flake/s) + (vals) + (async/to-chan!))) - s-asserts-out-ch (async/chan) + s-asserts-ch (s-flake-partitions assert-flakes) + s-retracts-ch (s-flake-partitions retract-flakes) + + s-asserts-out-ch (async/chan) s-retracts-out-ch (async/chan) - s-asserts-json-ch (async/into [] s-asserts-out-ch) + s-asserts-json-ch (async/into [] s-asserts-out-ch) s-retracts-json-ch (async/into [] s-retracts-out-ch)] ;; process asserts (async/pipeline-async 2 @@ -125,8 +127,8 @@ (async/pipe ch))) s-retracts-ch) {(json-ld/compact const/iri-t compact) (- (flake/t (first t-flakes))) - (json-ld/compact const/iri-assert compact) (json-ld [db q flakes] diff --git a/test/fluree/db/query/history_test.clj b/test/fluree/db/query/history_test.clj index 92af2299e..1c933c90e 100644 --- a/test/fluree/db/query/history_test.clj +++ b/test/fluree/db/query/history_test.clj @@ -23,9 +23,12 @@ :ex/y "bar-3"}) ts3 (-> db3 :commit :time) - db4 @(test-utils/transact ledger {:id :ex/cat - :ex/x "foo-cat" - :ex/y "bar-cat"}) + db4 @(test-utils/transact ledger [{:id :ex/cat + :ex/x "foo-cat" + :ex/y "bar-cat"} + {:id :ex/dog + :ex/x "foo-dog" + :ex/y "bar-dog"}]) db5 @(test-utils/transact ledger {:id :ex/dan :ex/x "foo-cat" :ex/y "bar-cat"})] @@ -74,7 +77,8 @@ :f/assert [{:ex/x "foo-cat" :id :ex/dan}] :f/retract [{:ex/x "foo-3" :id :ex/dan}]} {:f/t 4 - :f/assert [{:ex/x "foo-cat" :id :ex/cat}] + :f/assert [{:ex/x "foo-dog" :id :ex/dog} + {:ex/x "foo-cat" :id :ex/cat}] :f/retract []} {:f/t 3 :f/assert [{:ex/x "foo-3" :id :ex/dan}]