Separate feed entry id and entry_id

This commit is contained in:
Greg Shuflin 2025-02-04 22:21:40 -08:00
parent 2a11ae6d99
commit 7279ff3e2a
3 changed files with 13 additions and 5 deletions

View File

@ -4,10 +4,14 @@ _default:
# Don't use this secret key for your own install, it's public! # Don't use this secret key for your own install, it's public!
export SECRET_KEY := "MHSePvm1msyOkYuJ7u+MtyJYCzgdHCS7QNvrk9ts+rI=" export SECRET_KEY := "MHSePvm1msyOkYuJ7u+MtyJYCzgdHCS7QNvrk9ts+rI="
[doc("Run the reader locally in demo mode.")] # don't re-use this secret key [doc("Run the reader locally in demo mode.")]
run-local-demo *args: run-local-demo *args:
cargo run -- --demo {{args}} cargo run -- --demo {{args}}
# Run the reader locally against a persistent sqlite database
run-local-persistant-db *args:
cargo run -- --database data.sqlite
sqlx-prepare: sqlx-prepare:
DATABASE_URL="sqlite:data.sqlite" cargo sqlx prepare DATABASE_URL="sqlite:data.sqlite" cargo sqlx prepare

View File

@ -1,6 +1,7 @@
CREATE TABLE feed_entries ( CREATE TABLE feed_entries (
id TEXT PRIMARY KEY, id TEXT PRIMARY KEY,
feed_id TEXT NOT NULL, feed_id TEXT NOT NULL,
entry_id TEXT NOT NULL,
title TEXT NOT NULL, title TEXT NOT NULL,
published TIMESTAMP, published TIMESTAMP,
updated TIMESTAMP, updated TIMESTAMP,
@ -10,4 +11,4 @@ CREATE TABLE feed_entries (
created_at TIMESTAMP NOT NULL, created_at TIMESTAMP NOT NULL,
FOREIGN KEY (feed_id) REFERENCES feeds(feed_id) ON DELETE CASCADE, FOREIGN KEY (feed_id) REFERENCES feeds(feed_id) ON DELETE CASCADE,
UNIQUE(feed_id, id) UNIQUE(feed_id, id)
); );

View File

@ -21,7 +21,8 @@ pub struct FeedPollResponse {
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
#[serde(crate = "rocket::serde")] #[serde(crate = "rocket::serde")]
struct Entry { struct Entry {
id: String, id: Uuid,
entry_id: String,
title: String, title: String,
published: Option<DateTime<Utc>>, published: Option<DateTime<Utc>>,
updated: Option<DateTime<Utc>>, updated: Option<DateTime<Utc>>,
@ -52,7 +53,7 @@ async fn update_entry_db(
let result = sqlx::query( let result = sqlx::query(
r#" r#"
INSERT INTO feed_entries ( INSERT INTO feed_entries (
id, feed_id, title, published, updated, summary, content, link, created_at id, feed_id, entry_id, title, published, updated, summary, content, link, created_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (feed_id, id) DO UPDATE SET ON CONFLICT (feed_id, id) DO UPDATE SET
title = excluded.title, title = excluded.title,
@ -65,6 +66,7 @@ async fn update_entry_db(
) )
.bind(&entry.id) .bind(&entry.id)
.bind(feed_id) .bind(feed_id)
.bind(&entry.entry_id)
.bind(&entry.title) .bind(&entry.title)
.bind(entry.published.map(|dt| dt.to_rfc3339())) .bind(entry.published.map(|dt| dt.to_rfc3339()))
.bind(entry.updated.map(|dt| dt.to_rfc3339())) .bind(entry.updated.map(|dt| dt.to_rfc3339()))
@ -107,7 +109,8 @@ async fn fetch_new_entries(url: &Url) -> Result<Vec<Entry>, Status> {
.entries .entries
.into_iter() .into_iter()
.map(|feed_entry| Entry { .map(|feed_entry| Entry {
id: feed_entry.id, id: Uuid::new_v4(),
entry_id: feed_entry.id,
title: get(feed_entry.title, "title"), title: get(feed_entry.title, "title"),
published: feed_entry.published, published: feed_entry.published,
updated: feed_entry.updated, updated: feed_entry.updated,