fix: persist all mutations to capnp log
mark_used, mark_wrong, and decay all modified node state (weight, uses, wrongs, spaced_repetition_interval) only in memory + state.json. Like the categorize fix, these changes would be lost on cache rebuild. Now all three append updated node versions to the capnp log. Decay appends all nodes in one batch since it touches every node. Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
6322b3fd61
commit
c4d1675128
1 changed files with 21 additions and 2 deletions
|
|
@ -679,7 +679,7 @@ impl Store {
|
|||
}
|
||||
|
||||
pub fn mark_used(&mut self, key: &str) {
|
||||
if let Some(node) = self.nodes.get_mut(key) {
|
||||
let updated = if let Some(node) = self.nodes.get_mut(key) {
|
||||
node.uses += 1;
|
||||
node.weight = (node.weight + self.params.use_boost as f32).min(1.0);
|
||||
// Reset spaced repetition — used successfully, move up interval
|
||||
|
|
@ -689,15 +689,29 @@ impl Store {
|
|||
};
|
||||
}
|
||||
node.last_replayed = now_epoch();
|
||||
node.version += 1;
|
||||
Some(node.clone())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(node) = updated {
|
||||
let _ = self.append_nodes(&[node]);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mark_wrong(&mut self, key: &str, _ctx: Option<&str>) {
|
||||
if let Some(node) = self.nodes.get_mut(key) {
|
||||
let updated = if let Some(node) = self.nodes.get_mut(key) {
|
||||
node.wrongs += 1;
|
||||
node.weight = (node.weight - 0.1).max(0.0);
|
||||
// Reset spaced repetition interval — needs review
|
||||
node.spaced_repetition_interval = 1;
|
||||
node.version += 1;
|
||||
Some(node.clone())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(node) = updated {
|
||||
let _ = self.append_nodes(&[node]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -737,6 +751,7 @@ impl Store {
|
|||
for (key, node) in &mut self.nodes {
|
||||
let factor = node.category.decay_factor(base) as f32;
|
||||
node.weight *= factor;
|
||||
node.version += 1;
|
||||
decayed += 1;
|
||||
if node.weight < threshold {
|
||||
to_remove.push(key.clone());
|
||||
|
|
@ -752,6 +767,10 @@ impl Store {
|
|||
}
|
||||
}
|
||||
|
||||
// Persist all decayed weights to capnp log
|
||||
let updated: Vec<Node> = self.nodes.values().cloned().collect();
|
||||
let _ = self.append_nodes(&updated);
|
||||
|
||||
(decayed, pruned)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue