mirror of
https://github.com/ankitects/anki.git
synced 2025-12-12 22:36:55 -05:00
move html stripping out of field_checksum into caller
This commit is contained in:
parent
7eab504126
commit
cc54e92756
2 changed files with 22 additions and 13 deletions
|
|
@ -40,9 +40,10 @@ impl Note {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Text must be passed to strip_html_preserving_image_filenames() by
|
||||||
|
/// caller prior to passing in here.
|
||||||
pub(crate) fn field_checksum(text: &str) -> u32 {
|
pub(crate) fn field_checksum(text: &str) -> u32 {
|
||||||
let text = strip_html_preserving_image_filenames(text);
|
let digest = sha1::Sha1::from(text).digest().bytes();
|
||||||
let digest = sha1::Sha1::from(text.as_ref()).digest().bytes();
|
|
||||||
u32::from_be_bytes(digest[..4].try_into().unwrap())
|
u32::from_be_bytes(digest[..4].try_into().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,15 +120,20 @@ pub(super) fn set_note(db: &Connection, note: &mut Note, note_type: &NoteType) -
|
||||||
note.mtime_secs = i64_unix_secs();
|
note.mtime_secs = i64_unix_secs();
|
||||||
// hard-coded for now
|
// hard-coded for now
|
||||||
note.usn = -1;
|
note.usn = -1;
|
||||||
let csum = field_checksum(¬e.fields()[0]);
|
let field1_nohtml = strip_html_preserving_image_filenames(¬e.fields()[0]);
|
||||||
let sort_field = strip_html_preserving_image_filenames(
|
let csum = field_checksum(field1_nohtml.as_ref());
|
||||||
note.fields()
|
let sort_field = if note_type.sort_field_idx == 0 {
|
||||||
.get(note_type.sort_field_idx as usize)
|
field1_nohtml
|
||||||
.ok_or_else(|| AnkiError::DBError {
|
} else {
|
||||||
info: "sort field out of range".to_string(),
|
strip_html_preserving_image_filenames(
|
||||||
kind: DBErrorKind::MissingEntity,
|
note.fields()
|
||||||
})?,
|
.get(note_type.sort_field_idx as usize)
|
||||||
);
|
.ok_or_else(|| AnkiError::DBError {
|
||||||
|
info: "sort field out of range".to_string(),
|
||||||
|
kind: DBErrorKind::MissingEntity,
|
||||||
|
})?,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
let mut stmt =
|
let mut stmt =
|
||||||
db.prepare_cached("update notes set mod=?,usn=?,flds=?,sfld=?,csum=? where id=?")?;
|
db.prepare_cached("update notes set mod=?,usn=?,flds=?,sfld=?,csum=? where id=?")?;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@
|
||||||
use super::parser::{Node, PropertyKind, SearchNode, StateKind, TemplateKind};
|
use super::parser::{Node, PropertyKind, SearchNode, StateKind, TemplateKind};
|
||||||
use crate::card::CardQueue;
|
use crate::card::CardQueue;
|
||||||
use crate::notes::field_checksum;
|
use crate::notes::field_checksum;
|
||||||
use crate::{collection::RequestContext, types::ObjID};
|
use crate::{
|
||||||
|
collection::RequestContext, text::strip_html_preserving_image_filenames, types::ObjID,
|
||||||
|
};
|
||||||
use rusqlite::types::ToSqlOutput;
|
use rusqlite::types::ToSqlOutput;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
|
|
@ -240,7 +242,8 @@ fn write_single_field(ctx: &mut SearchContext, field: &str, val: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_dupes(ctx: &mut SearchContext, ntid: &ObjID, text: &str) {
|
fn write_dupes(ctx: &mut SearchContext, ntid: &ObjID, text: &str) {
|
||||||
let csum = field_checksum(text);
|
let text_nohtml = strip_html_preserving_image_filenames(text);
|
||||||
|
let csum = field_checksum(text_nohtml.as_ref());
|
||||||
write!(
|
write!(
|
||||||
ctx.sql,
|
ctx.sql,
|
||||||
"(n.mid = {} and n.csum = {} and field_at_index(n.flds, 0) = ?",
|
"(n.mid = {} and n.csum = {} and field_at_index(n.flds, 0) = ?",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue