mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
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:
parent
1b98e7e48f
commit
dee0a2fc18
7 changed files with 24 additions and 14 deletions
|
@ -202,7 +202,7 @@ impl Collection {
|
||||||
if deck.is_filtered() {
|
if deck.is_filtered() {
|
||||||
return Err(AnkiError::DeckIsFiltered);
|
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 sched = self.sched_ver();
|
||||||
let usn = self.usn()?;
|
let usn = self.usn()?;
|
||||||
self.transact(None, |col| {
|
self.transact(None, |col| {
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl Collection {
|
||||||
|
|
||||||
pub fn unbury_or_unsuspend_cards(&mut self, cids: &[CardID]) -> Result<()> {
|
pub fn unbury_or_unsuspend_cards(&mut self, cids: &[CardID]) -> Result<()> {
|
||||||
self.transact(None, |col| {
|
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()
|
col.unsuspend_or_unbury_searched_cards()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ impl Collection {
|
||||||
mode: pb::bury_or_suspend_cards_in::Mode,
|
mode: pb::bury_or_suspend_cards_in::Mode,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.transact(None, |col| {
|
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)
|
col.bury_or_suspend_searched_cards(mode)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,8 +72,8 @@ impl Collection {
|
||||||
let usn = self.usn()?;
|
let usn = self.usn()?;
|
||||||
let mut position = self.get_next_card_position();
|
let mut position = self.get_next_card_position();
|
||||||
self.transact(None, |col| {
|
self.transact(None, |col| {
|
||||||
col.storage.set_search_table_to_card_ids(cids)?;
|
col.storage.set_search_table_to_card_ids(cids, true)?;
|
||||||
let cards = col.storage.all_searched_cards()?;
|
let cards = col.storage.all_searched_cards_in_search_order()?;
|
||||||
for mut card in cards {
|
for mut card in cards {
|
||||||
let original = card.clone();
|
let original = card.clone();
|
||||||
col.log_manually_scheduled_review(&card, usn, 0)?;
|
col.log_manually_scheduled_review(&card, usn, 0)?;
|
||||||
|
@ -113,8 +113,8 @@ impl Collection {
|
||||||
if shift {
|
if shift {
|
||||||
self.shift_existing_cards(starting_from, step * cids.len() as u32, usn)?;
|
self.shift_existing_cards(starting_from, step * cids.len() as u32, usn)?;
|
||||||
}
|
}
|
||||||
self.storage.set_search_table_to_card_ids(cids)?;
|
self.storage.set_search_table_to_card_ids(cids, true)?;
|
||||||
let cards = self.storage.all_searched_cards()?;
|
let cards = self.storage.all_searched_cards_in_search_order()?;
|
||||||
let sorter = NewCardSorter::new(&cards, starting_from, step, random);
|
let sorter = NewCardSorter::new(&cards, starting_from, step, random);
|
||||||
for mut card in cards {
|
for mut card in cards {
|
||||||
let original = card.clone();
|
let original = card.clone();
|
||||||
|
@ -138,6 +138,7 @@ impl Collection {
|
||||||
card.set_new_position(card.due as u32 + by);
|
card.set_new_position(card.due as u32 + by);
|
||||||
self.update_card(&mut card, &original, usn)?;
|
self.update_card(&mut card, &original, usn)?;
|
||||||
}
|
}
|
||||||
|
self.storage.clear_searched_cards_table()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ impl Collection {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let distribution = Uniform::from(min_days..=max_days);
|
let distribution = Uniform::from(min_days..=max_days);
|
||||||
self.transact(None, |col| {
|
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()? {
|
for mut card in col.storage.all_searched_cards()? {
|
||||||
let original = card.clone();
|
let original = card.clone();
|
||||||
let interval = distribution.sample(&mut rng);
|
let interval = distribution.sample(&mut rng);
|
||||||
|
|
|
@ -267,7 +267,7 @@ impl super::SqliteStorage {
|
||||||
self.db
|
self.db
|
||||||
.prepare_cached(concat!(
|
.prepare_cached(concat!(
|
||||||
include_str!("get_card.sql"),
|
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))?
|
.query_and_then(NO_PARAMS, |r| row_to_card(r).map_err(Into::into))?
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -283,13 +283,14 @@ impl super::SqliteStorage {
|
||||||
.collect()
|
.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<()>
|
pub(crate) fn for_each_card_in_search<F>(&self, mut func: F) -> Result<()>
|
||||||
where
|
where
|
||||||
F: FnMut(Card) -> Result<()>,
|
F: FnMut(Card) -> Result<()>,
|
||||||
{
|
{
|
||||||
let mut stmt = self.db.prepare_cached(concat!(
|
let mut stmt = self.db.prepare_cached(concat!(
|
||||||
include_str!("get_card.sql"),
|
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)?;
|
let mut rows = stmt.query(NO_PARAMS)?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
|
@ -358,8 +359,16 @@ impl super::SqliteStorage {
|
||||||
/// Injects the provided card IDs into the search_cids table, for
|
/// Injects the provided card IDs into the search_cids table, for
|
||||||
/// when ids have arrived outside of a search.
|
/// when ids have arrived outside of a search.
|
||||||
/// Clear with clear_searched_cards().
|
/// Clear with clear_searched_cards().
|
||||||
pub(crate) fn set_search_table_to_card_ids(&mut self, cards: &[CardID]) -> Result<()> {
|
pub(crate) fn set_search_table_to_card_ids(
|
||||||
self.setup_searched_cards_table()?;
|
&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
|
let mut stmt = self
|
||||||
.db
|
.db
|
||||||
.prepare_cached("insert into search_cids values (?)")?;
|
.prepare_cached("insert into search_cids values (?)")?;
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
drop table if exists search_cids;
|
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);
|
|
@ -98,7 +98,7 @@ impl SqliteStorage {
|
||||||
self.db
|
self.db
|
||||||
.prepare_cached(concat!(
|
.prepare_cached(concat!(
|
||||||
include_str!("get.sql"),
|
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| {
|
.query_and_then(&[after.0 * 1000], |r| {
|
||||||
row_to_revlog_entry(r).map(Into::into)
|
row_to_revlog_entry(r).map(Into::into)
|
||||||
|
|
Loading…
Reference in a new issue