@@ -25,7 +25,7 @@ use crate::{
25
25
DownloadedWikipediaSuggestion , Record , SuggestRecordId ,
26
26
} ,
27
27
schema:: { clear_database, SuggestConnectionInitializer } ,
28
- suggestion:: { cook_raw_suggestion_url, AmpSuggestionType , Suggestion } ,
28
+ suggestion:: { cook_raw_suggestion_url, AmpSuggestionType , Suggestion , SuggestionIcon } ,
29
29
Result , SuggestionQuery ,
30
30
} ;
31
31
@@ -299,7 +299,7 @@ impl<'a> SuggestDao<'a> {
299
299
amp.iab_category,
300
300
amp.impression_url,
301
301
amp.click_url,
302
- i.data AS icon ,
302
+ i.data AS icon_data ,
303
303
i.mimetype AS icon_mimetype
304
304
FROM
305
305
amp_custom_details amp
@@ -315,6 +315,12 @@ impl<'a> SuggestDao<'a> {
315
315
let cooked_url = cook_raw_suggestion_url ( & raw_url) ;
316
316
let raw_click_url = row. get :: < _ , String > ( "click_url" ) ?;
317
317
let cooked_click_url = cook_raw_suggestion_url ( & raw_click_url) ;
318
+ let icon_data = row. get :: < _ , Option < _ > > ( "icon_data" ) ?;
319
+ let icon_mime_type = row. get :: < _ , Option < _ > > ( "icon_mimetype" ) ?;
320
+ let icon = icon_data. map ( |data| SuggestionIcon {
321
+ data,
322
+ mime_type : icon_mime_type. unwrap_or_default ( ) ,
323
+ } ) ;
318
324
319
325
Ok ( Suggestion :: Amp {
320
326
block_id : row. get ( "block_id" ) ?,
@@ -325,8 +331,7 @@ impl<'a> SuggestDao<'a> {
325
331
raw_url,
326
332
full_keyword : full_keyword_from_db
327
333
. unwrap_or_else ( || full_keyword ( keyword_lowercased, & keywords) ) ,
328
- icon : row. get ( "icon" ) ?,
329
- icon_mimetype : row. get ( "icon_mimetype" ) ?,
334
+ icon,
330
335
impression_url : row. get ( "impression_url" ) ?,
331
336
click_url : cooked_click_url,
332
337
raw_click_url,
@@ -378,7 +383,7 @@ impl<'a> SuggestDao<'a> {
378
383
} ,
379
384
|row| row. get ( 0 ) ,
380
385
) ?;
381
- let ( icon, icon_mimetype ) = self
386
+ let icon = self
382
387
. conn
383
388
. try_query_row (
384
389
"SELECT i.data, i.mimetype
@@ -390,21 +395,20 @@ impl<'a> SuggestDao<'a> {
390
395
":suggestion_id" : suggestion_id
391
396
} ,
392
397
|row| -> Result < _ > {
393
- Ok ( (
394
- row. get :: < _ , Option < Vec < u8 > > > ( 0 ) ?,
395
- row. get :: < _ , Option < String > > ( 1 ) ?,
396
- ) )
398
+ Ok ( Some ( SuggestionIcon {
399
+ data : row. get :: < _ , Vec < u8 > > ( 0 ) ?,
400
+ mime_type : row. get :: < _ , String > ( 1 ) ?,
401
+ } ) )
397
402
} ,
398
403
true ,
399
404
) ?
400
- . unwrap_or ( ( None , None ) ) ;
405
+ . unwrap_or ( None ) ;
401
406
402
407
Ok ( Suggestion :: Wikipedia {
403
408
title,
404
409
url : raw_url,
405
410
full_keyword : full_keyword ( keyword_lowercased, & keywords) ,
406
411
icon,
407
- icon_mimetype,
408
412
} )
409
413
} ,
410
414
) ?;
@@ -986,7 +990,7 @@ impl<'a> SuggestDao<'a> {
986
990
}
987
991
988
992
/// Inserts or replaces an icon for a suggestion into the database.
989
- pub fn put_icon ( & mut self , icon_id : & str , data : & [ u8 ] , mimetype : & str ) -> Result < ( ) > {
993
+ pub fn put_icon ( & mut self , icon_id : & str , data : & [ u8 ] , mime_type : & str ) -> Result < ( ) > {
990
994
self . conn . execute (
991
995
"INSERT OR REPLACE INTO icons(
992
996
id,
@@ -1001,7 +1005,7 @@ impl<'a> SuggestDao<'a> {
1001
1005
named_params ! {
1002
1006
":id" : icon_id,
1003
1007
":data" : data,
1004
- ":mimetype" : mimetype ,
1008
+ ":mimetype" : mime_type ,
1005
1009
} ,
1006
1010
) ?;
1007
1011
Ok ( ( ) )
0 commit comments