Skip to content

Commit

Permalink
fix(app): improve aggregate db write perf and remove polodb impl
Browse files Browse the repository at this point in the history
  • Loading branch information
rektdeckard committed Jun 13, 2024
1 parent a60fac4 commit 13cdba6
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 271 deletions.
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::config::Config;
use crate::feed::{Feed, Item};
use crate::repo::{storage::sqlite::SQLiteStorage, Repository, RepositoryEvent};
use crate::repo::{Repository, RepositoryEvent};
use anyhow::Result;
use clap::Parser;
use std::error;
Expand Down Expand Up @@ -93,7 +93,7 @@ impl FromStr for ConsoleCommand {
#[derive(Debug)]
pub struct App {
pub config: Config,
pub repo: Repository<SQLiteStorage>,
pub repo: Repository,
pub running: bool,
pub active_view: View,
pub active_tab: Tab,
Expand Down
15 changes: 8 additions & 7 deletions src/repo/repo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::RepositoryEvent;
use super::storage::sqlite::SQLiteStorage;
use crate::config::Config;
use crate::feed::Feed;
use crate::repo::storage::{Storage, StorageError, StorageEvent};
use crate::repo::storage::{StorageError, StorageEvent};
use crate::report;
use crate::util::sort_feeds;
use anyhow::Result;
Expand All @@ -21,24 +22,24 @@ enum FetchErr {
Parse,
}

pub struct Repository<S: Storage<StorageError>> {
storage: S,
pub struct Repository {
storage: SQLiteStorage,
app_tx: mpsc::UnboundedSender<RepositoryEvent>,
storage_tx: mpsc::UnboundedSender<RepositoryEvent>,
storage_rx: mpsc::UnboundedReceiver<RepositoryEvent>,
handle_one: Option<JoinHandle<()>>,
handle_many: Option<JoinHandle<()>>,
}

impl<S: Storage<StorageError>> Debug for Repository<S> {
impl Debug for Repository {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("Database {}")
}
}

impl<S: Storage<StorageError>> Repository<S> {
impl Repository {
pub fn init(config: &Config, app_tx: UnboundedSender<RepositoryEvent>) -> Result<Self> {
let storage = S::init(config);
let storage = SQLiteStorage::init(config);

let (storage_tx, storage_rx) = mpsc::unbounded_channel::<RepositoryEvent>();

Expand Down Expand Up @@ -76,7 +77,7 @@ impl<S: Storage<StorageError>> Repository<S> {
self.handle_many = None;
}
Some(RepositoryEvent::RetrievedOne(feed)) => {
report!(self.storage.write_feed(&feed), "Failed to write feed");
report!(self.storage.write_feed(&feed, None), "Failed to write feed");
self.app_tx
.send(RepositoryEvent::RetrievedOne(feed))
.expect("Failed to send app message");
Expand Down
14 changes: 0 additions & 14 deletions src/repo/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use crate::config::Config;
use crate::feed::{Feed, Item};

pub mod polo;
pub mod sqlite;

pub enum StorageEvent {
Expand All @@ -12,13 +8,3 @@ pub enum StorageEvent {
}

pub struct StorageError;

pub trait Storage<E: Sized> {
fn init(config: &Config) -> Self;
fn read_all(&mut self, config: &Config) -> Result<Vec<Feed>, E>;
fn read_items_for_feed_id(&self, id: &str) -> Result<Vec<Item>, E>;
fn write_feed(&self, feed: &Feed) -> Result<StorageEvent, E>;
fn write_feeds(&self, feeds: &Vec<Feed>) -> Result<Vec<StorageEvent>, E>;
fn write_item(&self, item: &Item) -> Result<StorageEvent, E>;
fn delete_feed_with_url(&self, url: &str) -> Result<StorageEvent, E>;
}
232 changes: 0 additions & 232 deletions src/repo/storage/polo.rs

This file was deleted.

Loading

0 comments on commit 13cdba6

Please sign in to comment.