MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / push

Method push

nodedb/src/control/trigger/batch/collector.rs:253–295  ·  view source on GitHub ↗

Push a row into the collector. Returns `Some(TriggerBatch)` if the push completes a batch (hit batch_size) or if the new row targets a different collection (flushes the old batch first).

(
        &mut self,
        collection: &str,
        operation: &str,
        tenant_id: u64,
        row: TriggerBatchRow,
    )

Source from the content-addressed store, hash-verified

251 /// Returns `Some(TriggerBatch)` if the push completes a batch (hit batch_size)
252 /// or if the new row targets a different collection (flushes the old batch first).
253 pub fn push(
254 &mut self,
255 collection: &str,
256 operation: &str,
257 tenant_id: u64,
258 row: TriggerBatchRow,
259 ) -> Option<TriggerBatch> {
260 // If the pending batch targets a different collection/operation, flush it first.
261 let flushed = if let Some(ref pending) = self.pending {
262 if pending.collection != collection || pending.operation != operation {
263 self.flush()
264 } else {
265 None
266 }
267 } else {
268 None
269 };
270
271 // Start new batch if needed.
272 if self.pending.is_none() {
273 self.pending = Some(PendingBatch {
274 collection: collection.to_string(),
275 operation: operation.to_string(),
276 tenant_id,
277 rows: Vec::with_capacity(self.batch_size),
278 });
279 }
280
281 // Add the row.
282 if let Some(ref mut pending) = self.pending {
283 pending.rows.push(row);
284
285 // If batch is full, flush it.
286 if pending.rows.len() >= self.batch_size {
287 let batch = self.flush();
288 // If we already flushed a different-collection batch, return that.
289 // The full batch will be returned on the next call or flush.
290 return flushed.or(batch);
291 }
292 }
293
294 flushed
295 }
296
297 /// Flush the pending batch, returning it if non-empty.
298 pub fn flush(&mut self) -> Option<TriggerBatch> {

Callers 15

addMethod · 0.45
merge_traversal_resultsFunction · 0.45
partition_local_remoteFunction · 0.45
run_checkpoint_cycleFunction · 0.45
read_dir_syncFunction · 0.45
listenMethod · 0.45
notifyMethod · 0.45
publishMethod · 0.45
subscribe_groupMethod · 0.45
convert_collection_typeFunction · 0.45
compute_tier_segmentsFunction · 0.45

Calls 4

to_stringMethod · 0.80
flushMethod · 0.45
lenMethod · 0.45
orMethod · 0.45