Skip to content

Commit a8d6392

Browse files
committed
No need for vg 'alias' to store/persist and reduces future flexibility
1 parent 8e3f7e5 commit a8d6392

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

src/fluree/db/flake/index/storage.cljc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@
179179
(loop [[[vg-alias storage-meta] & r] vg-address-map
180180
vg-map {}]
181181
(if vg-alias
182-
(let [vg (<? (vg/read-vg index-catalog storage-meta))]
183-
(recur r (assoc vg-map (:alias vg) vg)))
182+
(let [vg (<? (vg/read-vg index-catalog storage-meta))
183+
named-graph (vg/named-graph-alias vg)]
184+
(recur r (assoc vg-map named-graph vg)))
184185
vg-map))))
185186

186187
(defn read-db-root

src/fluree/db/virtual_graph.cljc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@
3434
(if (str/starts-with? vg-alias "##")
3535
(subs vg-alias 2)
3636
vg-alias))
37+
38+
(defn named-graph-alias
39+
"Returns the virtual graph's named graph alias
40+
41+
We currently use the syntax '##<vg-name>' for a named graph alias."
42+
[{:keys [vg-name] :as _vg}]
43+
(str "##" vg-name))

src/fluree/db/virtual_graph/bm25/index.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
(bm25-upsert* bm25 db nil items-ch)))
227227

228228
(defrecord BM25-VirtualGraph [id stemmer stopwords k1 b index-state initialized genesis-t t
229-
alias query parsed-query property-deps
229+
vg-name query parsed-query property-deps
230230
db-alias namespaces namespace-codes] ;; these items taken from db - is kept up to date with new db updates
231231

232232
iri/IRICodec

src/fluree/db/virtual_graph/bm25/storage.clj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
(defn vg-data
8989
[vg]
9090
(-> vg
91-
(select-keys [:k1 :b :index-state :initialized :genesis-t :t :alias :db-alias
91+
(select-keys [:k1 :b :index-state :initialized :genesis-t :t :db-alias
9292
:query :namespace-codes :property-deps :type :lang :id :vg-name])
9393
(update :id iri/serialize-sid)
9494
(update :index-state state-data)
@@ -109,23 +109,23 @@
109109
query-props (parse/get-query-props parsed-query)
110110
property-deps (get-property-sids namespaces query-props)]
111111
(-> vg-data
112-
(assoc :parsed-query parsed-query)
113-
(assoc :namespaces namespaces)
114-
(assoc :property-deps property-deps)
115-
(assoc :stemmer (stemmer/initialize lang))
116-
(assoc :stopwords (stopwords/initialize lang))
112+
(assoc :parsed-query parsed-query
113+
:namespaces namespaces
114+
:property-deps property-deps
115+
:stemmer (stemmer/initialize lang)
116+
:stopwords (stopwords/initialize lang))
117117
(update :id iri/deserialize-sid)
118118
(update :type (partial mapv iri/deserialize-sid))
119119
(update :index-state reify-state)
120120
(update :b coerce-double)
121121
(update :k1 coerce-double))))
122122

123123
(defmethod vg/write-vg :bm25
124-
[{:keys [storage serializer] :as _index-catalog} {:keys [alias db-alias] :as vg}]
124+
[{:keys [storage serializer] :as _index-catalog} {:keys [vg-name db-alias] :as vg}]
125125
(go-try
126126
(let [data (vg-data vg)
127127
serialized-data (serde/-serialize-bm25 serializer data)
128-
path (vg/storage-path :bm25 db-alias (vg/trim-alias-ref alias))
128+
path (vg/storage-path :bm25 db-alias vg-name)
129129
write-res (<? (storage/content-write-json storage path serialized-data))]
130130
(assoc write-res :type "bm25"))))
131131

src/fluree/db/virtual_graph/index_graph.cljc

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,14 @@
3838
:query nil}
3939
index-flakes))
4040

41-
(defn add-vg-id
42-
"Adds the full virtual graph IRI to the index options map"
43-
[{:keys [vg-name] :as idx-opts} db-alias]
44-
(let [vg-alias (str "##" vg-name)]
45-
(assoc idx-opts :alias vg-alias)))
46-
4741
#?(:clj
4842
(defn create
49-
[{:keys [alias t] :as db} vg-flakes]
43+
[{:keys [t] :as db} vg-flakes]
5044
(let [db-vol (volatile! db) ;; needed to potentially add new namespace codes based on query IRIs
5145

52-
{:keys [type alias] :as vg-opts}
46+
{:keys [type] :as vg-opts}
5347
(-> (idx-flakes->opts vg-flakes)
5448
(vg-parse/parse-document-query db-vol)
55-
(add-vg-id alias)
5649
(assoc :genesis-t t))
5750

5851
db* @db-vol
@@ -64,8 +57,8 @@
6457
:else (throw (ex-info "Unrecognized virtual graph creation attempted."
6558
{:status 400
6659
:error :db/invalid-index})))
67-
initialized-vg (vg/initialize vg db*)]
68-
[db* alias initialized-vg]))
60+
vg* (vg/initialize vg db*)]
61+
[db* vg*]))
6962

7063
:cljs
7164
(defn create
@@ -93,9 +86,9 @@
9386
;; at least currently, updates to vg are async
9487
;; and happen in background.
9588
(let [vg* (reduce-kv
96-
(fn [vg* vg-alias vg-impl]
97-
(log/debug "Virtual Graph update started for: " vg-alias)
98-
(assoc vg* vg-alias (vg/upsert vg-impl db add remove)))
89+
(fn [vg* named-graph vg-impl]
90+
(log/debug "Virtual Graph update started for: " named-graph)
91+
(assoc vg* named-graph (vg/upsert vg-impl db add remove)))
9992
{} vg)]
10093
(assoc db :vg vg*)))
10194

@@ -106,10 +99,11 @@
10699
(loop [[new-vg & r] new-vgs
107100
db db]
108101
(if new-vg
109-
(let [vg-flakes (filter #(= (flake/s %) new-vg) add)
110-
[db* alias vg-record] (create db vg-flakes)]
102+
(let [vg-flakes (filter #(= (flake/s %) new-vg) add)
103+
[db* vg] (create db vg-flakes)
104+
named-graph (vg/named-graph-alias vg)]
111105
;; TODO - VG - ensure alias is not being used, throw if so
112-
(recur r (assoc-in db* [:vg alias] vg-record)))
106+
(recur r (assoc-in db* [:vg named-graph] vg)))
113107
db)))
114108

115109
(defn has-vgs?

0 commit comments

Comments
 (0)