fix(anki): keep existing maturity tier on re-mined notes

- appendFromNoteInfo no longer overwrites a note's tracked tier with 'new' when the note already has one recorded
- add test covering re-mining a note that already has a mature/learning tier
This commit is contained in:
2026-07-23 01:41:14 -07:00
parent a173b108d1
commit f0e1cd6548
2 changed files with 35 additions and 1 deletions
@@ -342,3 +342,33 @@ test('appendFromNoteInfo marks freshly mined notes as new tier', async () => {
cleanup();
}
});
test('appendFromNoteInfo preserves an existing maturity tier', async () => {
const { manager, clientState, cleanup } = createMaturityHarness(maturityConfig());
try {
clientState.findNotesByQuery.set('deck:"Mining"', [7, 8]);
clientState.findNotesByQuery.set('deck:"Mining" prop:ivl>=21', [7]);
clientState.findNotesByQuery.set('deck:"Mining" prop:ivl>=1 prop:ivl<21', []);
clientState.findNotesByQuery.set('deck:"Mining" is:learn', [8]);
clientState.notesInfoResult = [
{ noteId: 7, fields: { Word: { value: '猫' } } },
{ noteId: 8, fields: { Word: { value: '犬' } } },
];
await manager.refresh(true);
manager.appendFromNoteInfo({
noteId: 7,
fields: { Word: { value: '子猫' } },
});
manager.appendFromNoteInfo({
noteId: 8,
fields: { Word: { value: '子犬' } },
});
assert.equal(manager.getKnownWordTier('子猫'), 'mature');
assert.equal(manager.getKnownWordTier('子犬'), 'learning');
} finally {
cleanup();
}
});
+5 -1
View File
@@ -342,7 +342,11 @@ export class KnownWordCacheManager {
}
// A just-mined card has never been reviewed.
if (this.isMaturityTrackingEnabled() && this.noteEntriesById.has(noteInfo.noteId)) {
if (
this.isMaturityTrackingEnabled() &&
this.noteEntriesById.has(noteInfo.noteId) &&
!this.noteTierById.has(noteInfo.noteId)
) {
this.noteTierById.set(noteInfo.noteId, 'new');
}