mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 10:26:21 +00:00
feat(blog::components::check_update) push frontmatter to database (metadata)
This commit is contained in:
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()));
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in new issue
Block a user