1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use anyhow::Result;
use crate::ctx::FrozenContext;
use crate::dbs::Options;
use crate::doc::Document;
impl Document {
pub async fn process_changefeeds(&self, ctx: &FrozenContext, opt: &Options) -> Result<()> {
// Check import
if opt.import {
return Ok(());
}
// Check if changed
if !self.is_modified() {
return Ok(());
}
// Get the namespace for this record
let ns = self.doc_ctx.ns();
// Get the database for this record
let db = self.doc_ctx.db();
// Get the table for this record
let tb = self.doc_ctx.tb()?;
// Get the changefeed definition on the database
let dbcf = db.changefeed.as_ref();
// Get the changefeed definition on the table
let tbcf = tb.changefeed.as_ref();
// Check if changefeeds are enabled
if let Some(cf) = dbcf.or(tbcf) {
// Create the changefeed entry
if let Some(id) = &self.id {
ctx.tx().changefeed_buffer_record_change(
ns.namespace_id,
db.database_id,
&tb.name,
id.as_ref(),
self.initial.doc.clone(),
self.current.doc.clone(),
cf.store_diff,
);
}
}
// Independently of the user-facing changefeed, capture a live-query event
// for this change when the Router engine is active and the table has
// subscribers. This writes to a dedicated keyspace (see [`crate::lq`]) and
// does not affect changefeed semantics, retention, or `SHOW CHANGES`.
self.process_live_events(ctx, opt).await?;
// Carry on
Ok(())
}
}