feat(blog::components::check_update) push frontmatter to database (metadata)

This commit is contained in:
lumither committed 2025-04-18 01:18:25 -07:00
1 parent e83cea1d42
commit 2c11af4a25
4 files changed
+32 -8

No files matched your search

@@ -18,6 +18,7 @@ const CREATE_RETURN_TAG_ID: &str = include_str!("sql/create_return_tag_id.sql");
const CREATE_RETURN_CATEGORY_ID: &str = include_str!("sql/create_return_category_id.sql"); const CREATE_RETURN_CATEGORY_ID: &str = include_str!("sql/create_return_category_id.sql");
const CREATE_POST_GENERAL: &str = include_str!("sql/create_post_general.sql"); const CREATE_POST_GENERAL: &str = include_str!("sql/create_post_general.sql");
const CREATE_POST_TAGS: &str = include_str!("sql/create_post_tags.sql"); const CREATE_POST_TAGS: &str = include_str!("sql/create_post_tags.sql");
const CREATE_POST_META: &str = include_str!("sql/create_post_meta.sql");
pub async fn apply_deltas(db_conn: &PgPool, changes: Vec<Change>) { pub async fn apply_deltas(db_conn: &PgPool, changes: Vec<Change>) {
let handlers = changes let handlers = changes
@@ -118,6 +119,19 @@ async fn handle_create(db: &PgPool, create: Create) {
} }
}; };
const KEY_TO_SKIP: &[&str] = &[
"category", "status", "id", "date", "update", "tags", "title", "subtitle",
];
let (post_meta_key, post_meta_value): (Vec<String>, Vec<String>) =
if let Some(kv) = create.payload.meta.as_object() {
kv.iter()
.filter(|(k, _)| !KEY_TO_SKIP.contains(&&***k))
.map(|(k, v)| (k.clone(), v.as_str().unwrap().to_string()))
.collect()
} else {
(vec![], vec![])
};
let meta = create.payload.meta; let meta = create.payload.meta;
let post_id = create.uuid; let post_id = create.uuid;
let post_identifier = &identifier; let post_identifier = &identifier;
@@ -174,6 +188,17 @@ async fn handle_create(db: &PgPool, create: Create) {
return; return;
} }
if let Err(e) = query(CREATE_POST_META)
.bind(post_id)
.bind(post_meta_key)
.bind(post_meta_value)
.execute(&mut *tx)
.await
{
error!("failed to insert post {}: {}", &identifier, e);
return;
}
tx.commit().await.unwrap(); tx.commit().await.unwrap();
} }
@@ -0,0 +1,3 @@
INSERT INTO metadata (pid, meta_key, meta_value)
SELECT $1, key, value
FROM UNNEST($2, $3) AS k(key, value);
@@ -1,9 +1,10 @@
use crate::modules::blog::components::consistency_guard::error::Error;
use std::{ use std::{
fs, fs,
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use crate::modules::blog::components::consistency_guard::error::Error;
pub fn rec_find_dir_entries(entry: &Path) -> Result<Vec<PathBuf>, Error> { pub fn rec_find_dir_entries(entry: &Path) -> Result<Vec<PathBuf>, Error> {
if !entry.exists() { if !entry.exists() {
return Err(Error::InvalidPath(entry.to_path_buf())); return Err(Error::InvalidPath(entry.to_path_buf()));
+2 -7
View File
@@ -5,12 +5,8 @@ use crate::{
modules::{ modules::{
Module, Module,
blog::{ blog::{
api::{ api::{get_page_count, get_post},
get_page_count, components::{check_update, consistency_guard},
get_post,
// get_post_list::get_post_list,
},
components::{check_update, consistency_guard}, // cron::check_update,
}, },
}, },
scheduler::tasks::{CronTask, async_basic::AsyncBasic}, scheduler::tasks::{CronTask, async_basic::AsyncBasic},
@@ -54,7 +50,6 @@ impl Module for Blog {
"Consistency Guard", "Consistency Guard",
AsyncBasic::new( AsyncBasic::new(
consistency_guard::task(db_handler.clone()), consistency_guard::task(db_handler.clone()),
// "*/15 * * * * *",
"*/15 * * * * *", "*/15 * * * * *",
) )
.unwrap() .unwrap()