pub fn load_cache() {
    let start = std::time::Instant::now();
    log::info!("Loading cache of posts...");

    let db = CONNECTION.lock();
    let db = &*db;

    let stmt = format!("SELECT * FROM posts");
    let mut stmt = match db.conn.prepare(&stmt) {
        Ok(val) => val,
        Err(err) => {
            log::error!("{:?}", err);
            return;
        }
    };

    let posts = error::helper(stmt.query_map(rusqlite::NO_PARAMS, |r| {
        let auth: String = r.get(1)?;
        let title: String = r.get(2)?;
        let body: String = r.get(3)?;
        let date: String = r.get(4)?;
        let tags: String = r.get(5)?;

        Ok(vec![
            auth.into(),
            title.into(),
            body.into(),
            date.into(),
            tags.into(),
        ])
    }))
    .map(|r| error::helper(r))
    .collect::<Vec<Vec<String>>>();

    let mut cache = CACHE.write();
    // Clear it out first
    *cache = BTreeMap::new();

    posts.iter().for_each(|post| {
        (*cache).entry(post[2].clone()).or_insert(post.clone());
    });

    log::info!(
        "Cache loaded. Elapsed time: {} ms",
        start.elapsed().as_millis()
    );
}
// Loads the posts from sqlite to memory.
Loads the posts from sqlite to memory.
Loads the posts from sqlite to memory .
pub fn load_cache() {
    let start = std::time::Instant::now();
    log::info!("Loading cache of posts...");
    let db = CONNECTION.lock();
    let db = &*db;
    let stmt = format!("SELECT * FROM posts");
    let mut stmt = match db.conn.prepare(&stmt) {
        Ok(val) => val,
        Err(err) => {
            log::error!("{:?}", err);
            return;
        }
    };
    let posts = error::helper(stmt.query_map(rusqlite::NO_PARAMS, |r| {
        let auth: String = r.get(1)?;
        let title: String = r.get(2)?;
        let body: String = r.get(3)?;
        let date: String = r.get(4)?;
        let tags: String = r.get(5)?;
        Ok(vec![
            auth.into(),
            title.into(),
            body.into(),
            date.into(),
            tags.into(),
        ])
    }))
    .map(|r| error::helper(r))
    .collect::<Vec<Vec<String>>>();
    let mut cache = CACHE.write();
    // Clear it out first
    *cache = BTreeMap::new();
    posts.iter().for_each(|post| {
        (*cache).entry(post[2].clone()).or_insert(post.clone());
    });
    log::info!(
        "Cache loaded. Elapsed time: {} ms",
        start.elapsed().as_millis()
    );
}
pub fn load_cache ( ) { let start = std :: time :: Instant :: now ( ) ; log :: info ! ( " " ) ; let db = CONNECTION . lock ( ) ; let db = & * db ; let stmt = format ! ( " " ) ; let mut stmt = match db . conn . prepare ( & stmt ) { Ok ( val ) => val , Err ( err ) => { log :: error ! ( " " err ) ; return ; } } ; let posts = error :: helper ( stmt . query_map ( rusqlite :: NO_PARAMS , | r | { let auth : String = r . get ( 1 ) ? ; let title : String = r . get ( 2 ) ? ; let body : String = r . get ( 3 ) ? ; let date : String = r . get ( 4 ) ? ; let tags : String = r . get ( 5 ) ? ; Ok ( vec ! [ auth into ( ) title into ( ) body into ( ) date into ( ) tags into ( ) ] ) } ) ) . map ( | r | error :: helper ( r ) ) . collect :: < Vec < Vec < String > > > ( ) ; let mut cache = CACHE . write ( ) ; // Clear it out first * cache = BTreeMap :: new ( ) ; posts . iter ( ) . for_each ( | post | { ( * cache ) . entry ( post [ 2 ] . clone ( ) ) . or_insert ( post . clone ( ) ) ; } ) ; log :: info ! ( " " start elapsed ( ) as_millis ( ) ) ; }
Loads the posts from sqlite to memory.
Loads the posts from sqlite to memory .