Pull in feeds on demo startup

This commit is contained in:
Greg Shuflin 2025-02-05 22:39:37 -08:00
parent 08994856c3
commit d7882b0291
3 changed files with 12 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"db_name": "SQLite",
"query": "\n SELECT \n id as \"id!: String\",\n local_id as \"local_id!: String\",\n title,\n published as \"published: Option<chrono::DateTime<Utc>>\",\n updated as \"updated: Option<chrono::DateTime<Utc>>\",\n summary,\n content,\n link,\n marked_read as \"marked_read: Option<chrono::DateTime<Utc>>\"\n FROM feed_entries \n WHERE feed_id = ?\n ORDER BY published DESC NULLS LAST\n LIMIT ?\n ",
"query": "\n SELECT \n id as \"id!: String\",\n local_id as \"local_id!: String\",\n title,\n published as \"published: Option<chrono::DateTime<Utc>>\",\n updated as \"updated: Option<chrono::DateTime<Utc>>\",\n summary,\n content,\n link,\n marked_read as \"marked_read: Option<chrono::DateTime<Utc>>\"\n FROM feed_entries\n WHERE feed_id = ?\n ORDER BY published DESC NULLS LAST\n LIMIT ?\n ",
"describe": {
"columns": [
{
@ -64,5 +64,5 @@
true
]
},
"hash": "2bbed6f20243ced25ac9359afefafb5ddffdff949250e0e4e35bf399fc0199fc"
"hash": "6186c55b12f42931e31a9f8367d6aa2bd637091ca9e1b8d9459241ca9488882c"
}

View File

@ -10,7 +10,7 @@ struct DemoFeed {
category: Option<&'static str>,
}
const DEMO_FEEDS: [DemoFeed; 5] = [
const DEMO_FEEDS: [DemoFeed; 6] = [
DemoFeed {
name: "XKCD",
url: "https://xkcd.com/atom.xml",
@ -31,6 +31,11 @@ const DEMO_FEEDS: [DemoFeed; 5] = [
url: "https://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml",
category: Some("News"),
},
DemoFeed {
name: "Lines and Colors",
url: "https://linesandcolors.com/feed/",
category: None,
},
DemoFeed {
name: "Astronomy Picture of the Day (APOD)",
url: "https://apod.nasa.gov/apod.rss",
@ -106,7 +111,7 @@ pub async fn setup_demo_data(pool: &sqlx::SqlitePool) {
"Successfully fetched {} entries",
entries.len()
);
if let Err(e) = update_entry_db(&entries, &feed_id, &*pool).await {
if let Err(e) = update_entry_db(&entries, &feed_id, pool).await {
warn!(error=%e, feed_url=url.as_str(), "Failed to store entries in database");
}
}

View File

@ -27,6 +27,7 @@ pub struct EntryStateUpdate {
}
async fn read_entries(feed_id: &Uuid, db: &mut SqliteConnection) -> Result<Vec<Entry>, Status> {
let feed_id_str = feed_id.to_string();
let rows = sqlx::query!(
r#"
SELECT
@ -39,12 +40,12 @@ async fn read_entries(feed_id: &Uuid, db: &mut SqliteConnection) -> Result<Vec<E
content,
link,
marked_read as "marked_read: Option<chrono::DateTime<Utc>>"
FROM feed_entries
FROM feed_entries
WHERE feed_id = ?
ORDER BY published DESC NULLS LAST
LIMIT ?
"#,
feed_id,
feed_id_str,
MAX_ENTRIES_PER_FEED,
)
.fetch_all(db)