mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
fix more issues uncovered by the latest clippy
This commit is contained in:
parent
dc81a7fed0
commit
1055acb9f2
19 changed files with 59 additions and 74 deletions
|
@ -51,9 +51,9 @@ impl From<pb::CardId> for CardId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<Vec<CardId>> for pb::CardIDs {
|
impl From<pb::CardIDs> for Vec<CardId> {
|
||||||
fn into(self) -> Vec<CardId> {
|
fn from(c: pb::CardIDs) -> Self {
|
||||||
self.cids.into_iter().map(CardId).collect()
|
c.cids.into_iter().map(CardId).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
// infallible backend methods still return a result
|
||||||
|
#![allow(clippy::unnecessary_wraps)]
|
||||||
|
#![allow(clippy::unknown_clippy_lints)]
|
||||||
|
|
||||||
mod adding;
|
mod adding;
|
||||||
mod card;
|
mod card;
|
||||||
mod cardrendering;
|
mod cardrendering;
|
||||||
|
|
|
@ -16,7 +16,7 @@ impl StatsService for Backend {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_graph_preferences(&self, _input: pb::Empty) -> Result<pb::GraphPreferences> {
|
fn get_graph_preferences(&self, _input: pb::Empty) -> Result<pb::GraphPreferences> {
|
||||||
self.with_col(|col| col.get_graph_preferences())
|
self.with_col(|col| Ok(col.get_graph_preferences()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_graph_preferences(&self, input: pb::GraphPreferences) -> Result<pb::Empty> {
|
fn set_graph_preferences(&self, input: pb::GraphPreferences) -> Result<pb::Empty> {
|
||||||
|
|
|
@ -103,7 +103,7 @@ impl Collection {
|
||||||
match res {
|
match res {
|
||||||
Ok(output) => {
|
Ok(output) => {
|
||||||
let changes = if op.is_some() {
|
let changes = if op.is_some() {
|
||||||
let changes = self.op_changes()?;
|
let changes = self.op_changes();
|
||||||
self.maybe_clear_study_queues_after_op(changes);
|
self.maybe_clear_study_queues_after_op(changes);
|
||||||
self.maybe_coalesce_note_undo_entry(changes);
|
self.maybe_coalesce_note_undo_entry(changes);
|
||||||
changes
|
changes
|
||||||
|
|
|
@ -192,7 +192,7 @@ delete from media where fname=?"
|
||||||
.query_row(
|
.query_row(
|
||||||
"select count(*) from media where csum is not null",
|
"select count(*) from media where csum is not null",
|
||||||
NO_PARAMS,
|
NO_PARAMS,
|
||||||
|row| Ok(row.get(0)?),
|
|row| row.get(0),
|
||||||
)
|
)
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,11 @@ pub(crate) fn normalize_nfc_filename(mut fname: Cow<str>) -> Cow<str> {
|
||||||
/// On Apple devices, the filename may be stored on disk in NFD encoding,
|
/// On Apple devices, the filename may be stored on disk in NFD encoding,
|
||||||
/// but can be accessed as NFC. On these devices, if the filename
|
/// but can be accessed as NFC. On these devices, if the filename
|
||||||
/// is otherwise valid, the filename is returned as NFC.
|
/// is otherwise valid, the filename is returned as NFC.
|
||||||
|
///
|
||||||
|
/// First two lints can be removed after updating to 1.51
|
||||||
|
#[allow(clippy::unknown_clippy_lints)]
|
||||||
#[allow(clippy::collapsible_if)]
|
#[allow(clippy::collapsible_if)]
|
||||||
|
#[allow(clippy::collapsible_else_if)]
|
||||||
pub(super) fn filename_if_normalized(fname: &str) -> Option<Cow<str>> {
|
pub(super) fn filename_if_normalized(fname: &str) -> Option<Cow<str>> {
|
||||||
if cfg!(target_vendor = "apple") {
|
if cfg!(target_vendor = "apple") {
|
||||||
if !is_nfc(fname) {
|
if !is_nfc(fname) {
|
||||||
|
|
|
@ -334,9 +334,8 @@ impl Collection {
|
||||||
|
|
||||||
fn default_deck_conf(&mut self) -> Result<(DeckId, DeckConfId)> {
|
fn default_deck_conf(&mut self) -> Result<(DeckId, DeckConfId)> {
|
||||||
// currently hard-coded to 1, we could create this as needed in the future
|
// currently hard-coded to 1, we could create this as needed in the future
|
||||||
Ok(self
|
self.deck_conf_if_normal(DeckId(1))?
|
||||||
.deck_conf_if_normal(DeckId(1))?
|
.ok_or_else(|| AnkiError::invalid_input("invalid default deck"))
|
||||||
.ok_or_else(|| AnkiError::invalid_input("invalid default deck"))?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If deck exists and and is a normal deck, return its ID and config
|
/// If deck exists and and is a normal deck, return its ID and config
|
||||||
|
|
|
@ -14,24 +14,19 @@ impl CardStateUpdater {
|
||||||
&mut self,
|
&mut self,
|
||||||
current: CardState,
|
current: CardState,
|
||||||
next: NewState,
|
next: NewState,
|
||||||
) -> Result<Option<RevlogEntryPartial>> {
|
) -> Option<RevlogEntryPartial> {
|
||||||
self.card.ctype = CardType::New;
|
self.card.ctype = CardType::New;
|
||||||
self.card.queue = CardQueue::New;
|
self.card.queue = CardQueue::New;
|
||||||
self.card.due = next.position as i32;
|
self.card.due = next.position as i32;
|
||||||
|
|
||||||
Ok(RevlogEntryPartial::maybe_new(
|
RevlogEntryPartial::maybe_new(current, next.into(), 0.0, self.secs_until_rollover())
|
||||||
current,
|
|
||||||
next.into(),
|
|
||||||
0.0,
|
|
||||||
self.secs_until_rollover(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn apply_learning_state(
|
pub(super) fn apply_learning_state(
|
||||||
&mut self,
|
&mut self,
|
||||||
current: CardState,
|
current: CardState,
|
||||||
next: LearnState,
|
next: LearnState,
|
||||||
) -> Result<Option<RevlogEntryPartial>> {
|
) -> Option<RevlogEntryPartial> {
|
||||||
self.card.remaining_steps = next.remaining_steps;
|
self.card.remaining_steps = next.remaining_steps;
|
||||||
self.card.ctype = CardType::Learn;
|
self.card.ctype = CardType::Learn;
|
||||||
|
|
||||||
|
@ -49,11 +44,6 @@ impl CardStateUpdater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(RevlogEntryPartial::maybe_new(
|
RevlogEntryPartial::maybe_new(current, next.into(), 0.0, self.secs_until_rollover())
|
||||||
current,
|
|
||||||
next.into(),
|
|
||||||
0.0,
|
|
||||||
self.secs_until_rollover(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ impl CardStateUpdater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}?;
|
};
|
||||||
|
|
||||||
Ok(revlog)
|
Ok(revlog)
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ impl CardStateUpdater {
|
||||||
&mut self,
|
&mut self,
|
||||||
current: CardState,
|
current: CardState,
|
||||||
next: NormalState,
|
next: NormalState,
|
||||||
) -> Result<Option<RevlogEntryPartial>> {
|
) -> Option<RevlogEntryPartial> {
|
||||||
self.card.reps += 1;
|
self.card.reps += 1;
|
||||||
self.card.original_due = 0;
|
self.card.original_due = 0;
|
||||||
|
|
||||||
|
@ -151,13 +151,13 @@ impl CardStateUpdater {
|
||||||
NormalState::Learning(next) => self.apply_learning_state(current, next),
|
NormalState::Learning(next) => self.apply_learning_state(current, next),
|
||||||
NormalState::Review(next) => self.apply_review_state(current, next),
|
NormalState::Review(next) => self.apply_review_state(current, next),
|
||||||
NormalState::Relearning(next) => self.apply_relearning_state(current, next),
|
NormalState::Relearning(next) => self.apply_relearning_state(current, next),
|
||||||
}?;
|
};
|
||||||
|
|
||||||
if next.leeched() && self.config.inner.leech_action() == LeechAction::Suspend {
|
if next.leeched() && self.config.inner.leech_action() == LeechAction::Suspend {
|
||||||
self.card.queue = CardQueue::Suspended;
|
self.card.queue = CardQueue::Suspended;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(revlog)
|
revlog
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_filtered(&self) -> Result<()> {
|
fn ensure_filtered(&self) -> Result<()> {
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
card::CardQueue,
|
card::CardQueue,
|
||||||
config::SchedulerVersion,
|
config::SchedulerVersion,
|
||||||
prelude::*,
|
|
||||||
scheduler::states::{CardState, IntervalKind, PreviewState},
|
scheduler::states::{CardState, IntervalKind, PreviewState},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,11 +16,11 @@ impl CardStateUpdater {
|
||||||
&mut self,
|
&mut self,
|
||||||
current: CardState,
|
current: CardState,
|
||||||
next: PreviewState,
|
next: PreviewState,
|
||||||
) -> Result<Option<RevlogEntryPartial>> {
|
) -> Option<RevlogEntryPartial> {
|
||||||
if next.finished {
|
if next.finished {
|
||||||
self.card
|
self.card
|
||||||
.remove_from_filtered_deck_restoring_queue(SchedulerVersion::V2);
|
.remove_from_filtered_deck_restoring_queue(SchedulerVersion::V2);
|
||||||
return Ok(None);
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.card.queue = CardQueue::PreviewRepeat;
|
self.card.queue = CardQueue::PreviewRepeat;
|
||||||
|
@ -36,18 +35,14 @@ impl CardStateUpdater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(RevlogEntryPartial::maybe_new(
|
RevlogEntryPartial::maybe_new(current, next.into(), 0.0, self.secs_until_rollover())
|
||||||
current,
|
|
||||||
next.into(),
|
|
||||||
0.0,
|
|
||||||
self.secs_until_rollover(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::collection::open_test_collection;
|
use crate::collection::open_test_collection;
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
@ -14,7 +14,7 @@ impl CardStateUpdater {
|
||||||
&mut self,
|
&mut self,
|
||||||
current: CardState,
|
current: CardState,
|
||||||
next: RelearnState,
|
next: RelearnState,
|
||||||
) -> Result<Option<RevlogEntryPartial>> {
|
) -> Option<RevlogEntryPartial> {
|
||||||
self.card.interval = next.review.scheduled_days;
|
self.card.interval = next.review.scheduled_days;
|
||||||
self.card.remaining_steps = next.learning.remaining_steps;
|
self.card.remaining_steps = next.learning.remaining_steps;
|
||||||
self.card.ctype = CardType::Relearn;
|
self.card.ctype = CardType::Relearn;
|
||||||
|
@ -34,11 +34,11 @@ impl CardStateUpdater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(RevlogEntryPartial::maybe_new(
|
RevlogEntryPartial::maybe_new(
|
||||||
current,
|
current,
|
||||||
next.into(),
|
next.into(),
|
||||||
next.review.ease_factor,
|
next.review.ease_factor,
|
||||||
self.secs_until_rollover(),
|
self.secs_until_rollover(),
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{CardQueue, CardType},
|
card::{CardQueue, CardType},
|
||||||
prelude::*,
|
|
||||||
scheduler::states::{CardState, ReviewState},
|
scheduler::states::{CardState, ReviewState},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,7 +13,7 @@ impl CardStateUpdater {
|
||||||
&mut self,
|
&mut self,
|
||||||
current: CardState,
|
current: CardState,
|
||||||
next: ReviewState,
|
next: ReviewState,
|
||||||
) -> Result<Option<RevlogEntryPartial>> {
|
) -> Option<RevlogEntryPartial> {
|
||||||
self.card.queue = CardQueue::Review;
|
self.card.queue = CardQueue::Review;
|
||||||
self.card.ctype = CardType::Review;
|
self.card.ctype = CardType::Review;
|
||||||
self.card.interval = next.scheduled_days;
|
self.card.interval = next.scheduled_days;
|
||||||
|
@ -22,11 +21,11 @@ impl CardStateUpdater {
|
||||||
self.card.ease_factor = (next.ease_factor * 1000.0).round() as u16;
|
self.card.ease_factor = (next.ease_factor * 1000.0).round() as u16;
|
||||||
self.card.lapses = next.lapses;
|
self.card.lapses = next.lapses;
|
||||||
|
|
||||||
Ok(RevlogEntryPartial::maybe_new(
|
RevlogEntryPartial::maybe_new(
|
||||||
current,
|
current,
|
||||||
next.into(),
|
next.into(),
|
||||||
next.ease_factor,
|
next.ease_factor,
|
||||||
self.secs_until_rollover(),
|
self.secs_until_rollover(),
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,11 +140,8 @@ impl Collection {
|
||||||
Ok(position)
|
Ok(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_next_filtered_deck_name(&self) -> Result<String> {
|
fn get_next_filtered_deck_name(&self) -> String {
|
||||||
Ok(format!(
|
format!("Filtered Deck {}", TimestampSecs::now().time_string())
|
||||||
"Filtered Deck {}",
|
|
||||||
TimestampSecs::now().time_string()
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_or_update_filtered_deck_inner(
|
fn add_or_update_filtered_deck_inner(
|
||||||
|
@ -203,7 +200,7 @@ impl Collection {
|
||||||
|
|
||||||
fn new_filtered_deck_for_adding(&mut self) -> Result<Deck> {
|
fn new_filtered_deck_for_adding(&mut self) -> Result<Deck> {
|
||||||
let mut deck = Deck {
|
let mut deck = Deck {
|
||||||
name: self.get_next_filtered_deck_name()?,
|
name: self.get_next_filtered_deck_name(),
|
||||||
..Deck::new_filtered()
|
..Deck::new_filtered()
|
||||||
};
|
};
|
||||||
if let Some(current) = self.get_deck(self.get_current_deck_id())? {
|
if let Some(current) = self.get_deck(self.get_current_deck_id())? {
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl Collection {
|
||||||
SortMode::Builtin { kind, reverse } => {
|
SortMode::Builtin { kind, reverse } => {
|
||||||
prepare_sort(self, kind)?;
|
prepare_sort(self, kind)?;
|
||||||
sql.push_str(" order by ");
|
sql.push_str(" order by ");
|
||||||
write_order(sql, kind, reverse)?;
|
write_order(sql, kind, reverse);
|
||||||
}
|
}
|
||||||
SortMode::Custom(order_clause) => {
|
SortMode::Custom(order_clause) => {
|
||||||
sql.push_str(" order by ");
|
sql.push_str(" order by ");
|
||||||
|
@ -135,7 +135,7 @@ impl Collection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add the order clause to the sql.
|
/// Add the order clause to the sql.
|
||||||
fn write_order(sql: &mut String, kind: SortKind, reverse: bool) -> Result<()> {
|
fn write_order(sql: &mut String, kind: SortKind, reverse: bool) {
|
||||||
let tmp_str;
|
let tmp_str;
|
||||||
let order = match kind {
|
let order = match kind {
|
||||||
SortKind::NoteCreation => "n.id asc, c.ord asc",
|
SortKind::NoteCreation => "n.id asc, c.ord asc",
|
||||||
|
@ -160,7 +160,7 @@ fn write_order(sql: &mut String, kind: SortKind, reverse: bool) -> Result<()> {
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
if order.is_empty() {
|
if order.is_empty() {
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
if reverse {
|
if reverse {
|
||||||
sql.push_str(
|
sql.push_str(
|
||||||
|
@ -172,7 +172,6 @@ fn write_order(sql: &mut String, kind: SortKind, reverse: bool) -> Result<()> {
|
||||||
} else {
|
} else {
|
||||||
sql.push_str(order);
|
sql.push_str(order);
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn needs_aux_sort_table(kind: SortKind) -> bool {
|
fn needs_aux_sort_table(kind: SortKind) -> bool {
|
||||||
|
|
|
@ -134,9 +134,9 @@ impl SqlWriter<'_> {
|
||||||
SearchNode::AddedInDays(days) => self.write_added(*days)?,
|
SearchNode::AddedInDays(days) => self.write_added(*days)?,
|
||||||
SearchNode::EditedInDays(days) => self.write_edited(*days)?,
|
SearchNode::EditedInDays(days) => self.write_edited(*days)?,
|
||||||
SearchNode::CardTemplate(template) => match template {
|
SearchNode::CardTemplate(template) => match template {
|
||||||
TemplateKind::Ordinal(_) => self.write_template(template)?,
|
TemplateKind::Ordinal(_) => self.write_template(template),
|
||||||
TemplateKind::Name(name) => {
|
TemplateKind::Name(name) => {
|
||||||
self.write_template(&TemplateKind::Name(norm(name).into()))?
|
self.write_template(&TemplateKind::Name(norm(name).into()))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
SearchNode::Deck(deck) => self.write_deck(&norm(deck))?,
|
SearchNode::Deck(deck) => self.write_deck(&norm(deck))?,
|
||||||
|
@ -146,10 +146,10 @@ impl SqlWriter<'_> {
|
||||||
SearchNode::DeckId(did) => {
|
SearchNode::DeckId(did) => {
|
||||||
write!(self.sql, "c.did = {}", did).unwrap();
|
write!(self.sql, "c.did = {}", did).unwrap();
|
||||||
}
|
}
|
||||||
SearchNode::NoteType(notetype) => self.write_note_type(&norm(notetype))?,
|
SearchNode::NoteType(notetype) => self.write_note_type(&norm(notetype)),
|
||||||
SearchNode::Rated { days, ease } => self.write_rated(">", -i64::from(*days), ease)?,
|
SearchNode::Rated { days, ease } => self.write_rated(">", -i64::from(*days), ease)?,
|
||||||
|
|
||||||
SearchNode::Tag(tag) => self.write_tag(&norm(tag))?,
|
SearchNode::Tag(tag) => self.write_tag(&norm(tag)),
|
||||||
SearchNode::State(state) => self.write_state(state)?,
|
SearchNode::State(state) => self.write_state(state)?,
|
||||||
SearchNode::Flag(flag) => {
|
SearchNode::Flag(flag) => {
|
||||||
write!(self.sql, "(c.flags & 7) == {}", flag).unwrap();
|
write!(self.sql, "(c.flags & 7) == {}", flag).unwrap();
|
||||||
|
@ -192,7 +192,7 @@ impl SqlWriter<'_> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_tag(&mut self, text: &str) -> Result<()> {
|
fn write_tag(&mut self, text: &str) {
|
||||||
if text.contains(' ') {
|
if text.contains(' ') {
|
||||||
write!(self.sql, "false").unwrap();
|
write!(self.sql, "false").unwrap();
|
||||||
} else {
|
} else {
|
||||||
|
@ -210,8 +210,6 @@ impl SqlWriter<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_rated(&mut self, op: &str, days: i64, ease: &RatingKind) -> Result<()> {
|
fn write_rated(&mut self, op: &str, days: i64, ease: &RatingKind) -> Result<()> {
|
||||||
|
@ -373,7 +371,7 @@ impl SqlWriter<'_> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_template(&mut self, template: &TemplateKind) -> Result<()> {
|
fn write_template(&mut self, template: &TemplateKind) {
|
||||||
match template {
|
match template {
|
||||||
TemplateKind::Ordinal(n) => {
|
TemplateKind::Ordinal(n) => {
|
||||||
write!(self.sql, "c.ord = {}", n).unwrap();
|
write!(self.sql, "c.ord = {}", n).unwrap();
|
||||||
|
@ -393,10 +391,9 @@ impl SqlWriter<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_note_type(&mut self, nt_name: &str) -> Result<()> {
|
fn write_note_type(&mut self, nt_name: &str) {
|
||||||
if is_glob(nt_name) {
|
if is_glob(nt_name) {
|
||||||
let re = format!("(?i){}", to_re(nt_name));
|
let re = format!("(?i){}", to_re(nt_name));
|
||||||
self.sql
|
self.sql
|
||||||
|
@ -407,7 +404,6 @@ impl SqlWriter<'_> {
|
||||||
.push_str("n.mid in (select id from notetypes where name = ?)");
|
.push_str("n.mid in (select id from notetypes where name = ?)");
|
||||||
self.args.push(to_text(nt_name).into());
|
self.args.push(to_text(nt_name).into());
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_single_field(&mut self, field_name: &str, val: &str, is_re: bool) -> Result<()> {
|
fn write_single_field(&mut self, field_name: &str, val: &str, is_re: bool) -> Result<()> {
|
||||||
|
|
|
@ -58,7 +58,7 @@ struct RevlogText {
|
||||||
impl Collection {
|
impl Collection {
|
||||||
pub fn card_stats(&mut self, cid: CardId) -> Result<String> {
|
pub fn card_stats(&mut self, cid: CardId) -> Result<String> {
|
||||||
let stats = self.gather_card_stats(cid)?;
|
let stats = self.gather_card_stats(cid)?;
|
||||||
self.card_stats_to_string(stats)
|
Ok(self.card_stats_to_string(stats))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gather_card_stats(&mut self, cid: CardId) -> Result<CardStats> {
|
fn gather_card_stats(&mut self, cid: CardId) -> Result<CardStats> {
|
||||||
|
@ -126,7 +126,7 @@ impl Collection {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn card_stats_to_string(&mut self, cs: CardStats) -> Result<String> {
|
fn card_stats_to_string(&mut self, cs: CardStats) -> String {
|
||||||
let tr = &self.tr;
|
let tr = &self.tr;
|
||||||
|
|
||||||
let mut stats = vec![(tr.card_stats_added().into(), cs.added.date_string())];
|
let mut stats = vec![(tr.card_stats_added().into(), cs.added.date_string())];
|
||||||
|
@ -194,13 +194,13 @@ impl Collection {
|
||||||
taken_secs: tr.card_stats_review_log_time_taken().into(),
|
taken_secs: tr.card_stats_review_log_time_taken().into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(CardStatsTemplate {
|
CardStatsTemplate {
|
||||||
stats,
|
stats,
|
||||||
revlog,
|
revlog,
|
||||||
revlog_titles,
|
revlog_titles,
|
||||||
}
|
}
|
||||||
.render()
|
.render()
|
||||||
.unwrap())
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,13 +51,13 @@ impl Collection {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_graph_preferences(&self) -> Result<pb::GraphPreferences> {
|
pub(crate) fn get_graph_preferences(&self) -> pb::GraphPreferences {
|
||||||
Ok(pb::GraphPreferences {
|
pb::GraphPreferences {
|
||||||
calendar_first_day_of_week: self.get_first_day_of_week() as i32,
|
calendar_first_day_of_week: self.get_first_day_of_week() as i32,
|
||||||
card_counts_separate_inactive: self.get_bool(BoolKey::CardCountsSeparateInactive),
|
card_counts_separate_inactive: self.get_bool(BoolKey::CardCountsSeparateInactive),
|
||||||
browser_links_supported: true,
|
browser_links_supported: true,
|
||||||
future_due_show_backlog: self.get_bool(BoolKey::FutureDueShowBacklog),
|
future_due_show_backlog: self.get_bool(BoolKey::FutureDueShowBacklog),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_graph_preferences(&mut self, prefs: pb::GraphPreferences) -> Result<()> {
|
pub(crate) fn set_graph_preferences(&mut self, prefs: pb::GraphPreferences) -> Result<()> {
|
||||||
|
|
|
@ -127,7 +127,9 @@ fn schema_version(db: &Connection) -> Result<(bool, u8)> {
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
false,
|
false,
|
||||||
db.query_row("select ver from col", NO_PARAMS, |r| Ok(r.get(0)?))?,
|
db.query_row("select ver from col", NO_PARAMS, |r| {
|
||||||
|
r.get(0).map_err(Into::into)
|
||||||
|
})?,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -228,8 +228,8 @@ impl Collection {
|
||||||
|
|
||||||
/// Return changes made by the current op. Must only be called in a transaction,
|
/// Return changes made by the current op. Must only be called in a transaction,
|
||||||
/// when an operation was passed to transact().
|
/// when an operation was passed to transact().
|
||||||
pub(crate) fn op_changes(&self) -> Result<OpChanges> {
|
pub(crate) fn op_changes(&self) -> OpChanges {
|
||||||
Ok(self.state.undo.op_changes())
|
self.state.undo.op_changes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue