@@ -27,7 +27,7 @@ use crate::{
27
27
} ,
28
28
schema:: { clear_database, SuggestConnectionInitializer , VERSION } ,
29
29
store:: { UnparsableRecord , UnparsableRecords } ,
30
- suggestion:: { cook_raw_suggestion_url, AmpSuggestionType , Suggestion } ,
30
+ suggestion:: { cook_raw_suggestion_url, AmpSuggestionType , Suggestion , SuggestionIcon } ,
31
31
Result , SuggestionQuery ,
32
32
} ;
33
33
@@ -290,7 +290,7 @@ impl<'a> SuggestDao<'a> {
290
290
amp.iab_category,
291
291
amp.impression_url,
292
292
amp.click_url,
293
- i.data AS icon ,
293
+ i.data AS icon_data ,
294
294
i.mimetype AS icon_mimetype
295
295
FROM
296
296
amp_custom_details amp
@@ -306,6 +306,12 @@ impl<'a> SuggestDao<'a> {
306
306
let cooked_url = cook_raw_suggestion_url ( & raw_url) ;
307
307
let raw_click_url = row. get :: < _ , String > ( "click_url" ) ?;
308
308
let cooked_click_url = cook_raw_suggestion_url ( & raw_click_url) ;
309
+ let icon_data = row. get :: < _ , Option < _ > > ( "icon_data" ) ?;
310
+ let icon_mime_type = row. get :: < _ , Option < _ > > ( "icon_mimetype" ) ?;
311
+ let icon = icon_data. map ( |data| SuggestionIcon {
312
+ data,
313
+ mime_type : icon_mime_type. unwrap_or_default ( ) ,
314
+ } ) ;
309
315
310
316
Ok ( Suggestion :: Amp {
311
317
block_id : row. get ( "block_id" ) ?,
@@ -316,8 +322,7 @@ impl<'a> SuggestDao<'a> {
316
322
raw_url,
317
323
full_keyword : full_keyword_from_db
318
324
. unwrap_or_else ( || full_keyword ( keyword_lowercased, & keywords) ) ,
319
- icon : row. get ( "icon" ) ?,
320
- icon_mimetype : row. get ( "icon_mimetype" ) ?,
325
+ icon,
321
326
impression_url : row. get ( "impression_url" ) ?,
322
327
click_url : cooked_click_url,
323
328
raw_click_url,
@@ -368,7 +373,7 @@ impl<'a> SuggestDao<'a> {
368
373
} ,
369
374
|row| row. get ( 0 ) ,
370
375
) ?;
371
- let ( icon, icon_mimetype ) = self
376
+ let icon = self
372
377
. conn
373
378
. try_query_row (
374
379
"SELECT i.data, i.mimetype
@@ -380,21 +385,20 @@ impl<'a> SuggestDao<'a> {
380
385
":suggestion_id" : suggestion_id
381
386
} ,
382
387
|row| -> Result < _ > {
383
- Ok ( (
384
- row. get :: < _ , Option < Vec < u8 > > > ( 0 ) ?,
385
- row. get :: < _ , Option < String > > ( 1 ) ?,
386
- ) )
388
+ Ok ( Some ( SuggestionIcon {
389
+ data : row. get :: < _ , Vec < u8 > > ( 0 ) ?,
390
+ mime_type : row. get :: < _ , String > ( 1 ) ?,
391
+ } ) )
387
392
} ,
388
393
true ,
389
394
) ?
390
- . unwrap_or ( ( None , None ) ) ;
395
+ . unwrap_or ( None ) ;
391
396
392
397
Ok ( Suggestion :: Wikipedia {
393
398
title,
394
399
url : raw_url,
395
400
full_keyword : full_keyword ( keyword_lowercased, & keywords) ,
396
401
icon,
397
- icon_mimetype,
398
402
} )
399
403
} ,
400
404
) ?;
@@ -1171,7 +1175,7 @@ impl<'a> SuggestDao<'a> {
1171
1175
}
1172
1176
1173
1177
/// Inserts or replaces an icon for a suggestion into the database.
1174
- pub fn put_icon ( & mut self , icon_id : & str , data : & [ u8 ] , mimetype : & str ) -> Result < ( ) > {
1178
+ pub fn put_icon ( & mut self , icon_id : & str , data : & [ u8 ] , mime_type : & str ) -> Result < ( ) > {
1175
1179
self . conn . execute (
1176
1180
"INSERT OR REPLACE INTO icons(
1177
1181
id,
@@ -1186,7 +1190,7 @@ impl<'a> SuggestDao<'a> {
1186
1190
named_params ! {
1187
1191
":id" : icon_id,
1188
1192
":data" : data,
1189
- ":mimetype" : mimetype ,
1193
+ ":mimetype" : mime_type ,
1190
1194
} ,
1191
1195
) ?;
1192
1196
Ok ( ( ) )
0 commit comments