Decode list_ranked_articles rows via a From<Row> impl
Replaces the inline .map() closure with From<Row> for RankedArticleRow, separating "what a raw SQLite row looks like" from the query itself.
This commit is contained in:
parent
e70909af47
commit
cc79f59a7d
1 changed files with 19 additions and 15 deletions
|
|
@ -108,7 +108,6 @@ impl Db {
|
|||
if let Some(feed_id) = feed_id {
|
||||
query = query.filter(dsl::feed_id.eq(feed_id.to_string()));
|
||||
}
|
||||
type Row = (String, String, String, String, String, String, Option<f32>);
|
||||
let rows: Vec<Row> = query
|
||||
.order(dsl::final_score.desc())
|
||||
.limit(limit)
|
||||
|
|
@ -123,20 +122,25 @@ impl Db {
|
|||
))
|
||||
.load(&mut conn)
|
||||
.await?;
|
||||
Ok(rows
|
||||
.into_iter()
|
||||
.map(
|
||||
|(id, feed_id, title, url, summary, topics_json, final_score)| RankedArticleRow {
|
||||
id,
|
||||
feed_id,
|
||||
title,
|
||||
url,
|
||||
summary,
|
||||
topics: serde_json::from_str(&topics_json).unwrap_or_default(),
|
||||
final_score,
|
||||
},
|
||||
)
|
||||
.collect())
|
||||
Ok(rows.into_iter().map(RankedArticleRow::from).collect())
|
||||
}
|
||||
}
|
||||
|
||||
/// Raw shape of one `list_ranked_articles` row as loaded from SQLite —
|
||||
/// `topics` is still the JSON string column, not yet decoded.
|
||||
type Row = (String, String, String, String, String, String, Option<f32>);
|
||||
|
||||
impl From<Row> for RankedArticleRow {
|
||||
fn from((id, feed_id, title, url, summary, topics_json, final_score): Row) -> Self {
|
||||
Self {
|
||||
id,
|
||||
feed_id,
|
||||
title,
|
||||
url,
|
||||
summary,
|
||||
topics: serde_json::from_str(&topics_json).unwrap_or_default(),
|
||||
final_score,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue