In this PR, I add last_review_time
to card data for performance and accuracy:
main
ā L-M-Sherlock:Add-last_review_time-field-to-card-data
opened 09:53AM - 24 Jun 25 UTC
### Background
Currently, Anki has two main issues when determining the last ⦠review time of a card:
1. **Performance Issue**: Querying the revision log (revlog) to get the last review time is expensive and slow for batch processing
2. **Accuracy Issue**: Calculating the last review time from `due` and `interval` fields can be inaccurate, especially when the they have been modified by `set_due_date` or changed by add-ons
### Changes
This PR introduces a new `last_review_time` field to the Card structure that directly stores the timestamp of when a card was last reviewed.
**Key Changes:**
1. **Schema Update**: Added `optional int64 last_review_time_secs = 23` to the protobuf definition
2. **Field Addition**: Added `last_review_time: Option<TimestampSecs>` to the Rust Card struct and related data structures
3. **Storage Integration**: Updated serialization/deserialization logic to handle the new field
4. **Review Logic**: Set `last_review_time` during card answering to capture the exact review timestamp
5. **Calculation Updates**: Modified functions that calculate days/seconds since last review to prioritize the new field over legacy calculation methods
**Affected Areas:**
- Card protobuf definition
- Card data structures and serialization
- Browser table calculations
- Scheduling logic
- Statistics calculations
- Sync functionality
### Benefits
1. **Improved Performance**: Eliminates expensive revlog queries when calculating time since last review
2. **Better Accuracy**: Stores the exact review timestamp instead of inferring it from due dates and intervals
3. **Backward Compatibility**: Falls back to the existing calculation methods when `last_review_time` is not available
fix #4091
But the last_review_time
field is assigned only when the user reviews an existing cards. It will take a long to fill them all.
When last_review_time
field is empty, the retrievability sorting can be wrong if the user applied set due date
in an older version of Anki:
So, how about filling the last_review_time
field of card when Check Database
? We can fill the field by querying the revlog table to get the correct value.
4 Likes
main
ā Luc-Mcgrady:Feat/card-stats-update-last-review-time
opened 12:05PM - 29 Jul 25 UTC
Updates the `last_review_time` of a card when opening the stats menu as the valu⦠e is calculated anyway.
I'm not sure if you're comfortable having `card_stats` modify the database but if you are here you go :)
How about saving the review time when its calculated in card_stats as well?
jhhr
July 30, 2025, 1:11pm
4
Is the last_review_time
going to be available in the states
provided to the custom scheduling JS? Iām currently implementing the last review time myself in card.custom_data
and it would nice if that was no longer necessary.
I recommend opening a new post to suggest it.