mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 15:26:17 +00:00
fix(ffi): invalidate the graph cache on same-millisecond synapse fires
A visit that re-fires a synapse in the same millisecond as its last fire kept the synapse count and max(last_fired) unchanged, so graph_data() served a stale graph (and cache_is_invalidated_by_edits_and_visits failed intermittently). The cache key now includes the total synapse weight. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f8fe17b50f
commit
265a411f4d
1 file changed
+13
-3
@@ -19,6 +19,9 @@ pub struct CacheKey {
|
||||
seq: i64,
|
||||
synapses: i64,
|
||||
synapse_last: i64,
|
||||
/// Sum of raw weights (micro-units): a re-fire within the same millisecond keeps count
|
||||
/// and `last_fired` but changes the weight.
|
||||
synapse_weight: i64,
|
||||
/// Synapse weights decay with time: rebuild at least hourly.
|
||||
hour: i64,
|
||||
}
|
||||
@@ -47,15 +50,22 @@ impl SynapseGraph {
|
||||
}
|
||||
|
||||
fn cache_key(g: &Graph) -> Result<CacheKey> {
|
||||
let (synapses, synapse_last) = g.conn().query_row(
|
||||
"SELECT count(*), coalesce(max(last_fired), 0) FROM synapses",
|
||||
let (synapses, synapse_last, weight) = g.conn().query_row(
|
||||
"SELECT count(*), coalesce(max(last_fired), 0), total(weight) FROM synapses",
|
||||
[],
|
||||
|r| Ok((r.get::<_, i64>(0)?, r.get::<_, i64>(1)?)),
|
||||
|r| {
|
||||
Ok((
|
||||
r.get::<_, i64>(0)?,
|
||||
r.get::<_, i64>(1)?,
|
||||
r.get::<_, f64>(2)?,
|
||||
))
|
||||
},
|
||||
)?;
|
||||
Ok(CacheKey {
|
||||
seq: g.last_seq()?,
|
||||
synapses,
|
||||
synapse_last,
|
||||
synapse_weight: (weight * 1e6).round() as i64,
|
||||
hour: g.now_ms() / 3_600_000,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user