Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Rule cache #602

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ out/
/datahike
datahike.build_artifacts.txt
tests.user.edn
/libdatahike/target
/libdatahike/target
/resources/DATAHIKE_VERSION
tmp.edn
3 changes: 1 addition & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
org.clojure/tools.cli {:mvn/version "1.0.206"}
incanter/incanter-core {:mvn/version "1.9.3"}
incanter/incanter-charts {:mvn/version "1.9.3"}
hashp/hashp {:mvn/version "0.2.2"}}
:main-opts ["-e" "(require 'hashp.core)"]}
hashp/hashp {:mvn/version "0.2.2"}}}

:test {:extra-paths ["test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.70.1086"}
Expand Down
3 changes: 2 additions & 1 deletion dev/user.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns user
(:require [datahike.api :as d]))
(:require [datahike.api :as d]
[hashp.core]))

(comment

Expand Down
13 changes: 12 additions & 1 deletion src/datahike/api.cljc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns datahike.api
(:refer-clojure :exclude [filter])
(:require [datahike.connector :as dc]
(:require [datahike.config :as config]
[datahike.connector :as dc]
[datahike.constants :as const]
[datahike.core :as dcore]
[datahike.pull-api :as dp]
Expand Down Expand Up @@ -262,6 +263,10 @@
Query passed as map needs vectors as values. Query can not be passed as list. The 1-arity function takes a map with the arguments :query and :args and optionally the additional keys :offset and :limit."}
q dq/q)

(def ^{:arglists '([query & args] [arg-map])
:doc "Executes a datalog query and returns the result as well as some execution details."}
query-stats dq/query-stats)

(defmulti datoms {:arglists '([db arg-map] [db index & components])
:doc "Index lookup. Returns a sequence of datoms (lazy iterator over actual DB index) which components
(e, a, v) match passed arguments. Datoms are sorted in index sort order. Possible `index` values
Expand Down Expand Up @@ -808,3 +813,9 @@
[db]
{:pre [(instance? DB db)]}
(db/metrics db))

(defn ^{:arglists '([])
:doc "Loads default config for the current environment"}
load-config
[]
(config/load-config))
11 changes: 5 additions & 6 deletions src/datahike/middleware/query.cljc
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
(ns datahike.middleware.query
(:require [clojure.pprint :as pprint]))
(:require [clojure.pprint :as pprint]
[datahike.tools :as dt]))

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn timed-query [query-handler]
(fn [query & inputs]
(let [start (. System (nanoTime))
result (apply query-handler query inputs)
t (/ (double (- (. System (nanoTime)) start)) 1000000.0)]
(let [{:keys [t res]} (dt/timed #(apply query-handler query inputs))]
(println "Query time:")
(pprint/pprint {:t t
:q (update query :args str)
:inputs (str inputs)})
result)))

res)))
Loading