Skip to content

Commit

Permalink
Remove MutableTaskCache trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Garfield committed Mar 1, 2022
1 parent c1fd121 commit 55116c2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
14 changes: 4 additions & 10 deletions bot/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@ pub struct TaskCache {
pub index: HashMap<i64, HashSet<Pubkey>>,
}

pub trait MutableTaskCache {
fn new() -> TaskCache;
fn insert(&mut self, key: Pubkey, task: Task);
fn delete(&mut self, key: Pubkey);
}

impl MutableTaskCache for TaskCache {
fn new() -> TaskCache {
impl TaskCache {
pub fn new() -> TaskCache {
TaskCache {
data: HashMap::new(),
index: HashMap::new(),
}
}

fn insert(&mut self, key: Pubkey, task: Task) {
pub fn insert(&mut self, key: Pubkey, task: Task) {
self.delete(key);
self.data.insert(key, task.clone());

Expand All @@ -38,7 +32,7 @@ impl MutableTaskCache for TaskCache {
}
}

fn delete(&mut self, key: Pubkey) {
pub fn delete(&mut self, key: Pubkey) {
self.data.clone().get(&key).and_then(|task| {
self.data.remove(&key);
self.index
Expand Down
1 change: 0 additions & 1 deletion bot/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::sync::{Arc, Mutex, RwLock};
use std::thread::{self, JoinHandle};

use crate::bucket::Bucket;
use crate::cache::MutableTaskCache;
use crate::utils::sign_and_submit;
use crate::{cache::TaskCache, utils::monitor_blocktime};

Expand Down
2 changes: 1 addition & 1 deletion bot/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::{Arc, Mutex, RwLock};

use bucket::Bucket;
use cache::{MutableTaskCache, TaskCache};
use cache::TaskCache;
use dotenv::dotenv;
use solana_client_helpers::ClientResult;
use utils::new_rpc_client;
Expand Down
5 changes: 1 addition & 4 deletions bot/src/replicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ use std::{
thread,
};

use crate::{
cache::{MutableTaskCache, TaskCache},
env,
};
use crate::{cache::TaskCache, env};

pub fn replicate_tasks(cache: Arc<RwLock<TaskCache>>) {
thread::spawn(move || {
Expand Down

0 comments on commit 55116c2

Please sign in to comment.