1
1
use alive_lock_file:: LockResultWithDrop ;
2
2
use derivative:: Derivative ;
3
3
use futures:: StreamExt ;
4
- use itertools:: Itertools ;
5
4
use sqlx:: { migrate:: MigrateDatabase , prelude:: * , Sqlite , SqliteConnection } ;
6
5
use std:: {
7
6
cell:: RefCell ,
@@ -23,7 +22,7 @@ use crate::{
23
22
utils:: { self } ,
24
23
} ;
25
24
26
- use super :: { now, DbMessage , DbTrait , EntryId , EntryTrait , MimeDataMap } ;
25
+ use super :: { now, DbMessage , DbTrait , EntryId , EntryTrait , MimeDataMap , PRIV_MIME_TYPES_SIMPLE } ;
27
26
28
27
type Time = i64 ;
29
28
@@ -49,11 +48,11 @@ pub struct DbSqlite {
49
48
lock : Option < LockResultWithDrop > ,
50
49
}
51
50
52
- #[ derive( Clone , Eq , Derivative ) ]
51
+ #[ derive( Clone , Derivative ) ]
53
52
pub struct Entry {
54
53
pub id : EntryId ,
55
54
pub creation : Time ,
56
- // todo: lazelly load image in memory, since we can't search them anyways
55
+ // todo: lazelly load image in memory, since we can't search them anyways?
57
56
/// (Mime, Content)
58
57
pub raw_content : MimeDataMap ,
59
58
pub is_favorite : bool ,
@@ -107,11 +106,21 @@ impl Favorites {
107
106
}
108
107
109
108
fn hash_entry_content < H : Hasher > ( data : & MimeDataMap , state : & mut H ) {
110
- data. iter ( )
111
- . sorted_by ( |e1, e2| e1. 0 . cmp ( e2. 0 ) )
112
- . for_each ( |e| {
113
- e. hash ( state) ;
114
- } ) ;
109
+ for m in PRIV_MIME_TYPES_SIMPLE {
110
+ if let Some ( content) = data. get ( * m) {
111
+ if !content. is_empty ( ) {
112
+ content. hash ( state) ;
113
+ return ;
114
+ }
115
+ }
116
+ }
117
+
118
+ let mut sorted = data. iter ( ) . collect :: < Vec < _ > > ( ) ;
119
+ sorted. sort_by ( |( mime1, _) , ( mime2, _) | mime1. cmp ( mime2) ) ;
120
+
121
+ for ( _, content) in sorted {
122
+ content. hash ( state) ;
123
+ }
115
124
}
116
125
117
126
fn get_hash_entry_content ( data : & MimeDataMap ) -> u64 {
@@ -126,12 +135,6 @@ impl Hash for Entry {
126
135
}
127
136
}
128
137
129
- impl PartialEq for Entry {
130
- fn eq ( & self , other : & Self ) -> bool {
131
- self . id == other. id
132
- }
133
- }
134
-
135
138
impl EntryTrait for Entry {
136
139
fn is_favorite ( & self ) -> bool {
137
140
self . is_favorite
@@ -424,6 +427,7 @@ impl DbTrait for DbSqlite {
424
427
425
428
if let Some ( id) = self . hashs . get ( & hash) {
426
429
let entry = self . entries . get_mut ( id) . unwrap ( ) ;
430
+
427
431
let old_creation = entry. creation ;
428
432
entry. creation = now;
429
433
let res = self . times . remove ( & old_creation) ;
0 commit comments