-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix #19225: refresh queue on note edit #20114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix #19225: refresh queue on note edit #20114
Conversation
what do you mean by that? |
|
When we edit the note, the card's mod time changes in the DB, but the scheduler's queue cache is still holding the old state. If we don't force refresh it, backend detects this mismatch (DB vs Cache) when we try to undo, it triggers the "card modified without updating queue" error. |
|
A test would make this easier to review |
0d22112 to
c13d904
Compare
|
Added the test case in ReviewerViewModelTest.kt. It verifies that the card state refreshes correctly after a template modification |
|
|
||
| @Before | ||
| fun setup() { | ||
| Dispatchers.setMain(StandardTestDispatcher()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was the boilerplate, but now base class already handles dispatcher setup, so it's removed now.
| val viewModel = ReviewerViewModel(handle) | ||
|
|
||
| advanceUntilIdle() | ||
| advanceRobolectricLooper() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not necessary as test uses a dispatcher that executes tasks immediately here.
| val notetype = note.notetype | ||
| val tmpls = notetype.templates | ||
| val tmpl = tmpls.first() | ||
| tmpl.qfmt = tmpl.qfmt + " Modified" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+=
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated it as you suggested in next push.
| val newCard = viewModel.currentCard.await() | ||
| assertThat("Card should be refreshed (new instance)", newCard, not(sameInstance(card))) | ||
|
|
||
| viewModel.answerCard(Rating.GOOD) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably be asserting something. If not: assertDoesNotThrow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, i added assertDoesNotThrow.
| val card = viewModel.currentCard.await() | ||
| val note = card.note() | ||
| val notetype = note.notetype | ||
| val tmpls = notetype.templates | ||
| val tmpl = tmpls.first() | ||
| tmpl.qfmt = tmpl.qfmt + " Modified" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very verbose, how about:
viewModel.currentCard.await().noteType().update {
templates.first().qfmt += " Modified"
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I used noteType().update approach which is much cleaner. I kept the initial val card = as I'm using it for not(sameInstance(card)) assertion later to check that card instance actually refreshes or not.
7bedddd to
2e9f1ea
Compare
Prevent 'card modified without updating queue' error by refreshing state when note text changes.
Fix #19225: Refresh queue on note edit
Issue
Fixes #19225
Problem
Editing a note or template in the new reviewer desyncs the backend queue state. Attempting to Undo afterwards trigger a
bug: card modified without updating queueerror and messes up the review counts.Solution
Force updateCurrentCard() when
OpChanges.noteTextfires. This ensures we refresh the queue state from the backend whenever the card content changes.Testing
Added ReviewerViewModelTest which reproduces the issue by simulating a template edit and verifying that the
currentCardinstance is correctly refreshed from the backend.ReviewerViewModelTest.editing note template updates queue state preventing undo errorpasses.