fix reposition not being applied in browser sort order

https://forums.ankiweb.net/t/reposition-function-not-working/5817

Also changed id->cid in the non-sorting case, as otherwise when
using all_searched_cards() on a sorted list, the results will be wrong.
This commit is contained in:
Damien Elmes 2020-12-16 10:54:10 +10:00
parent 1b98e7e48f
commit dee0a2fc18
7 changed files with 24 additions and 14 deletions

View File

@ -202,7 +202,7 @@ impl Collection {
if deck.is_filtered() {
return Err(AnkiError::DeckIsFiltered);
}
self.storage.set_search_table_to_card_ids(cards)?;
self.storage.set_search_table_to_card_ids(cards, false)?;
let sched = self.sched_ver();
let usn = self.usn()?;
self.transact(None, |col| {

View File

@ -83,7 +83,7 @@ impl Collection {
pub fn unbury_or_unsuspend_cards(&mut self, cids: &[CardID]) -> Result<()> {
self.transact(None, |col| {
col.storage.set_search_table_to_card_ids(cids)?;
col.storage.set_search_table_to_card_ids(cids, false)?;
col.unsuspend_or_unbury_searched_cards()
})
}
@ -143,7 +143,7 @@ impl Collection {
mode: pb::bury_or_suspend_cards_in::Mode,
) -> Result<()> {
self.transact(None, |col| {
col.storage.set_search_table_to_card_ids(cids)?;
col.storage.set_search_table_to_card_ids(cids, false)?;
col.bury_or_suspend_searched_cards(mode)
})
}

View File

@ -72,8 +72,8 @@ impl Collection {
let usn = self.usn()?;
let mut position = self.get_next_card_position();
self.transact(None, |col| {
col.storage.set_search_table_to_card_ids(cids)?;
let cards = col.storage.all_searched_cards()?;
col.storage.set_search_table_to_card_ids(cids, true)?;
let cards = col.storage.all_searched_cards_in_search_order()?;
for mut card in cards {
let original = card.clone();
col.log_manually_scheduled_review(&card, usn, 0)?;
@ -113,8 +113,8 @@ impl Collection {
if shift {
self.shift_existing_cards(starting_from, step * cids.len() as u32, usn)?;
}
self.storage.set_search_table_to_card_ids(cids)?;
let cards = self.storage.all_searched_cards()?;
self.storage.set_search_table_to_card_ids(cids, true)?;
let cards = self.storage.all_searched_cards_in_search_order()?;
let sorter = NewCardSorter::new(&cards, starting_from, step, random);
for mut card in cards {
let original = card.clone();
@ -138,6 +138,7 @@ impl Collection {
card.set_new_position(card.due as u32 + by);
self.update_card(&mut card, &original, usn)?;
}
self.storage.clear_searched_cards_table()?;
Ok(())
}
}

View File

@ -36,7 +36,7 @@ impl Collection {
let mut rng = rand::thread_rng();
let distribution = Uniform::from(min_days..=max_days);
self.transact(None, |col| {
col.storage.set_search_table_to_card_ids(cids)?;
col.storage.set_search_table_to_card_ids(cids, false)?;
for mut card in col.storage.all_searched_cards()? {
let original = card.clone();
let interval = distribution.sample(&mut rng);

View File

@ -267,7 +267,7 @@ impl super::SqliteStorage {
self.db
.prepare_cached(concat!(
include_str!("get_card.sql"),
" where id in (select id from search_cids)"
" where id in (select cid from search_cids)"
))?
.query_and_then(NO_PARAMS, |r| row_to_card(r).map_err(Into::into))?
.collect()
@ -283,13 +283,14 @@ impl super::SqliteStorage {
.collect()
}
/// Cards will arrive in card id order, not search order.
pub(crate) fn for_each_card_in_search<F>(&self, mut func: F) -> Result<()>
where
F: FnMut(Card) -> Result<()>,
{
let mut stmt = self.db.prepare_cached(concat!(
include_str!("get_card.sql"),
" where id in (select id from search_cids)"
" where id in (select cid from search_cids)"
))?;
let mut rows = stmt.query(NO_PARAMS)?;
while let Some(row) = rows.next()? {
@ -358,8 +359,16 @@ impl super::SqliteStorage {
/// Injects the provided card IDs into the search_cids table, for
/// when ids have arrived outside of a search.
/// Clear with clear_searched_cards().
pub(crate) fn set_search_table_to_card_ids(&mut self, cards: &[CardID]) -> Result<()> {
self.setup_searched_cards_table()?;
pub(crate) fn set_search_table_to_card_ids(
&mut self,
cards: &[CardID],
preserve_order: bool,
) -> Result<()> {
if preserve_order {
self.setup_searched_cards_table_to_preserve_order()?;
} else {
self.setup_searched_cards_table()?;
}
let mut stmt = self
.db
.prepare_cached("insert into search_cids values (?)")?;

View File

@ -1,2 +1,2 @@
drop table if exists search_cids;
create temporary table search_cids (id integer primary key not null);
create temporary table search_cids (cid integer primary key not null);

View File

@ -98,7 +98,7 @@ impl SqliteStorage {
self.db
.prepare_cached(concat!(
include_str!("get.sql"),
" where cid in (select id from search_cids) and id >= ?"
" where cid in (select cid from search_cids) and id >= ?"
))?
.query_and_then(&[after.0 * 1000], |r| {
row_to_revlog_entry(r).map(Into::into)