File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3939 "mocha" : " ^2.3.4"
4040 },
4141 "scripts" : {
42+ "build" : " cd .. && lein cljsbuild once min && cd release-js" ,
4243 "test" : " mocha --harmony --compilers js:babel-core/register test/*.spec.js"
4344 },
4445 "files" : [
Original file line number Diff line number Diff line change 1+ import { helpers , mori } from '../datascript-mori'
2+ import { assert } from 'chai'
3+
4+ describe ( 'memoized_parse checks' , ( ) => {
5+ it ( 'memoized_parse work as mori.parse' , ( ) => {
6+ const query = `[:find ?e1 ?e2 ?e3
7+ :where [?e1 :age ?a1]
8+ [?e2 :age ?a2]
9+ [?e3 :age ?a3]
10+ [(+ ?a1 ?a2) ?a12]
11+ [(= ?a12 ?a3)]]`
12+
13+ assert (
14+ mori . equals ( helpers . memoized_parse ( query ) , mori . parse ( query ) ) ,
15+ 'memoized_parse and mori.parse return equal struct'
16+ ) ;
17+ } )
18+ } ) ;
Original file line number Diff line number Diff line change 55 [datascript.parser :as dp]
66 [datascript.pull-parser :as dpp]
77 [mori :as m]
8- [mori.extra :as me]))
8+ [mori.extra :as me]
9+ [cljs.reader :as reader]
10+ [datascript.lru :as dlru]))
911
1012(def ^:export schema_to_clj djs /schema->clj )
1113(def ^:export entity_to_clj djs /entity->clj )
1921(def ^:export parse_query dp /parse-query )
2022(def ^:export parse_pull dpp /parse-pull )
2123
24+ (def ^:const lru-cache-size 300 )
25+ (def ^:export lru dlru /lru )
26+ (def ^:export cleanup_lru dlru /cleanup-lru )
27+ (def ^:export query_cache (volatile! (dlru/lru lru-cache-size)))
28+ (defn ^:export memoized_parse [q]
29+ (if-let [cached (get @query_cache q nil )]
30+ cached
31+ (let [qp (reader/read-string q)]
32+ (vswap! query_cache assoc q qp)
33+ qp)))
34+
2235(def ^:export DB_ID :db/id )
2336(def ^:export DB_FN_CALL :db.fn/call )
2437(def ^:export DB_BEFORE :db-before )
You can’t perform that action at this time.
0 commit comments