Skip to content

Commit

Permalink
feat: purge articles
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglun committed Dec 8, 2023
1 parent a26f8f5 commit d631928
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
33 changes: 33 additions & 0 deletions src-tauri/src/feed/article.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use chrono::{Utc, Duration};
use diesel::prelude::*;
use diesel::sql_types::*;
use serde::{Deserialize, Serialize};
use crate::core::config::get_user_config;

use crate::db::establish_connection;
use crate::models;
Expand Down Expand Up @@ -437,4 +439,35 @@ impl Article {
return 0;
}
}

pub fn purge_articles() -> usize {
let user_config = get_user_config();

if let Some(cfg) = user_config {
if cfg.purge_on_days == 0 {
return 0;
}

let expired_date = Utc::now().naive_utc() - Duration::days(cfg.purge_on_days as i64);
let mut connection = establish_connection();
let mut query = diesel::delete(schema::articles::dsl::articles).into_boxed();

if !cfg.purge_unread_articles {
query = query.filter(schema::articles::read_status.eq(2));
}

let query = query
.filter(schema::articles::create_date.lt(expired_date));

let result = query
.execute(&mut connection)
.expect("purge failed!");

log::info!("{:?} articles purged", result);

return result;
}

0
}
}
2 changes: 2 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ async fn main() {
server::init(*boxed_handle).unwrap();
});

feed::article::Article::purge_articles();

Ok(())
})
.on_menu_event(core::menu::AppMenu::on_menu_event)
Expand Down
2 changes: 1 addition & 1 deletion src/components/ArticleItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const ArticleItem = React.forwardRef(
alt=""
className="rounded w-4 mr-1"
/>
<span className="overflow-hidden text-ellipsis mr-1 whitespace-nowrap">
<span className="max-w-[146px] overflow-hidden text-ellipsis mr-1 whitespace-nowrap">
{article.author || article.feed_title}
</span>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Subscribes/ItemView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const ItemView: FC<CardProps> = ({
>
<div
className={clsx(
"w-full h-9 px-4 rounded-md flex items-center cursor-pointer group text-foreground hover:bg-accent",
"w-full h-9 px-3 rounded-md flex items-center cursor-pointer group text-foreground hover:bg-accent",
{
"hover:bg-primary bg-primary text-primary-foreground": isActive,
"shadow-[inset_0_0_0_2px_var(--color-primary)]":
Expand Down Expand Up @@ -96,7 +96,7 @@ export const ItemView: FC<CardProps> = ({
{feed.link && (
<img
src={ico}
className="h-4 w-4 rounded mr-2"
className="h-5 w-5 rounded mr-2"
alt={feed.title}
/>
)}
Expand All @@ -113,7 +113,7 @@ export const ItemView: FC<CardProps> = ({
{unread > 0 && (
<span
className={clsx(
"-mr-2 min-w-[1rem] h-4 leading-4 text-center text-[10px]",
"-mr-1 min-w-[1rem] h-4 leading-4 text-center text-[10px]",
{
"text-primary-foreground": isActive,
}
Expand Down

0 comments on commit d631928

Please sign in to comment.