MCPcopy Create free account
hub / github.com/Rustixir/darkbird / insert

Method insert

src/darkbird/storage.rs:125–175  ·  view source on GitHub ↗
(&self, key: K, doc: Doc)

Source from the content-addressed store, hash-verified

123 /// insert to storage and persist to disk
124 #[inline]
125 pub async fn insert(&self, key: K, doc: Doc) -> Result<(), SessionResult> {
126
127 if !self.off_disk || !self.off_reporter {
128 let query = RQuery::Insert(key.clone(), doc.clone());
129
130 if !self.off_disk {
131 if let Err(e) = self.wal_session.log(bincode::serialize(&query).unwrap()).await {
132 return Err(e);
133 }
134 }
135
136 if !self.off_reporter {
137 let _ = self.reporter_session.dispatch(Event::Query(query)).await;
138 }
139
140 }
141
142
143 // Insert to indexes
144 if let Err(e) = self.hash_index.insert(&key, &doc) {
145 return Err(SessionResult::Err(e))
146 }
147
148
149 // Insert to view
150 if let Some(view_name) = doc.filter() {
151 self.tag_index.insert_view(&view_name, &key)
152 }
153
154
155 // Insert to InvertedIndex
156 if let Some(content) = doc.get_content() {
157 let _ = self.inverted_index.insert(key.clone(), content).await;
158 }
159
160
161 // Insert to tag_index
162 self.tag_index.insert(&key, &doc);
163
164
165 // Insert to range
166 self.range_index.insert(&key, &doc);
167
168
169 // Insert to memory
170 self.collection.insert(key, doc);
171
172 Ok(())
173
174
175 }
176
177 /// remove from storage and persist to disk
178 #[inline]

Callers 15

mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
vectorFunction · 0.45
setMethod · 0.45
set_nxMethod · 0.45

Calls 5

logMethod · 0.80
dispatchMethod · 0.80
insert_viewMethod · 0.80
filterMethod · 0.45
get_contentMethod · 0.45

Tested by 1

vectorFunction · 0.36