mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 15:26:17 +00:00
fix(ffi): graph cache also keys on total synapse weight (flaky cache test)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ada391a88e
commit
5e5e1ba925
1 file changed
+14
-3
@@ -19,6 +19,9 @@ pub struct CacheKey {
|
||||
seq: i64,
|
||||
synapses: i64,
|
||||
synapse_last: i64,
|
||||
/// Total weight (micro-units): a visit can strengthen an existing synapse within the same
|
||||
/// millisecond as its last firing, which leaves count and `last_fired` unchanged.
|
||||
synapse_weight: i64,
|
||||
/// Synapse weights decay with time: rebuild at least hourly.
|
||||
hour: i64,
|
||||
}
|
||||
@@ -47,15 +50,23 @@ 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, synapse_weight) = g.conn().query_row(
|
||||
"SELECT count(*), coalesce(max(last_fired), 0),
|
||||
coalesce(CAST(sum(weight) * 1000000 AS INTEGER), 0) FROM synapses",
|
||||
[],
|
||||
|r| Ok((r.get::<_, i64>(0)?, r.get::<_, i64>(1)?)),
|
||||
|r| {
|
||||
Ok((
|
||||
r.get::<_, i64>(0)?,
|
||||
r.get::<_, i64>(1)?,
|
||||
r.get::<_, i64>(2)?,
|
||||
))
|
||||
},
|
||||
)?;
|
||||
Ok(CacheKey {
|
||||
seq: g.last_seq()?,
|
||||
synapses,
|
||||
synapse_last,
|
||||
synapse_weight,
|
||||
hour: g.now_ms() / 3_600_000,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user