Browse Source

cache: First steps to use lmdb cache

environments/review-revert-691-44rtr0/deployments/27
Daniel García Moreno 8 years ago
parent
commit
ada758a33a
  1. 47
      Cargo.lock
  2. 2
      fractal-gtk/Cargo.toml
  3. 2
      fractal-gtk/po/POTFILES.in
  4. 34
      fractal-gtk/src/cache/mod.rs
  5. 5
      fractal-gtk/src/main.rs

47
Cargo.lock generated

@ -100,6 +100,15 @@ dependencies = [
"safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bincode"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "1.0.4"
@ -402,9 +411,11 @@ dependencies = [
"gtk 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"html2pango 0.1.0 (git+https://gitlab.gnome.org/World/html2pango)",
"itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"letter-avatar 0.1.1 (git+https://gitlab.gnome.org/danigm/letter-avatar.git?branch=updatedep)",
"libhandy 0.2.0 (git+https://gitlab.gnome.org/jsparber/libhandy-rs)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"mdl 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"notify-rust 3.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"pango 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pangocairo 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1018,6 +1029,26 @@ dependencies = [
"memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lmdb"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"lmdb-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lmdb-sys"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "locale_config"
version = "0.2.2"
@ -1100,6 +1131,18 @@ name = "md5"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "mdl"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lmdb 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memchr"
version = "2.1.0"
@ -2419,6 +2462,7 @@ dependencies = [
"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
"checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643"
"checksum bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9f2fb9e29e72fd6bc12071533d5dc7664cb01480c59406f656d7ac25c7bd8ff7"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400"
"checksum block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
@ -2505,6 +2549,8 @@ dependencies = [
"checksum libflate 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "21138fc6669f438ed7ae3559d5789a5f0ba32f28c1f0608d1e452b0bb06ee936"
"checksum libhandy 0.2.0 (git+https://gitlab.gnome.org/jsparber/libhandy-rs)" = "<none>"
"checksum linkify 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9ce9439c6f4a1092dc1861272bef01034891da39f13aa1cdcf40ca3e4081de5f"
"checksum lmdb 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b0908efb5d6496aa977d96f91413da2635a902e5e31dbef0bfb88986c248539"
"checksum lmdb-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5b392838cfe8858e86fac37cf97a0e8c55cc60ba0a18365cadc33092f128ce9"
"checksum locale_config 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "14fbee0e39bc2dd6a2427c4fdea66e9826cc1fd09b0a0b7550359f5f6efe1dab"
"checksum lock_api 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "775751a3e69bde4df9b38dd00a1b5d6ac13791e4223d4a0506577f0dd27cfb7a"
"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f"
@ -2515,6 +2561,7 @@ dependencies = [
"checksum markup5ever 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfedc97d5a503e96816d10fedcd5b42f760b2e525ce2f7ec71f6a41780548475"
"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
"checksum md5 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "995999bcecec06dff8499bfafab45119c1d33a57d75a705b429d6d49f38c2f40"
"checksum mdl 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b9ab681f8a6f741dd30a3f4f103b35b3e92fa510e0ef82ee83833819cf739b75"
"checksum memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b3629fe9fdbff6daa6c33b90f7c08355c1aca05a3d01fa8063b822fcf185f3b"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum mime 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "4b082692d3f6cf41b453af73839ce3dfc212c4411cbb2441dff80a716e38bd79"

2
fractal-gtk/Cargo.toml

@ -34,6 +34,8 @@ letter-avatar = { git = "https://gitlab.gnome.org/danigm/letter-avatar.git", bra
sourceview = "0.5.0"
itertools = "0.7.8"
dirs = "1.0.3"
mdl = "1.0.4"
lazy_static = "1.1.0"
[dependencies.cairo-rs]
features = ["png"]

2
fractal-gtk/po/POTFILES.in

@ -75,7 +75,7 @@ fractal-gtk/src/appop/state.rs
fractal-gtk/src/appop/stickers.rs
fractal-gtk/src/appop/sync.rs
fractal-gtk/src/appop/user.rs
fractal-gtk/src/cache.rs
fractal-gtk/src/cache/mod.rs
fractal-gtk/src/globals.rs
fractal-gtk/src/main.rs
fractal-gtk/src/passwd.rs

34
fractal-gtk/src/cache.rs → fractal-gtk/src/cache/mod.rs vendored

@ -1,11 +1,10 @@
extern crate serde_json;
use std::fs::File;
use std::fs::remove_dir_all;
use std::io::prelude::*;
use gtk;
use gtk::LabelExt;
use serde_json;
use types::RoomList;
use error::Error;
@ -23,6 +22,10 @@ use std::cell::RefCell;
use std::rc::Rc;
use widgets::AvatarData;
use mdl;
use std::sync::{Arc, Mutex, MutexGuard};
#[derive(Serialize, Deserialize)]
pub struct CacheData {
pub since: Option<String>,
@ -145,3 +148,30 @@ pub fn download_to_cache_username_emote(backend: Sender<BKCommand>,
}
});
}
#[derive(Clone)]
pub struct FCache {
cache: Arc<Mutex<mdl::Cache>>,
}
impl FCache {
pub fn c(&self) -> MutexGuard<mdl::Cache> {
self.cache.lock().unwrap()
}
}
// The cache object, it's the same for the whole process
lazy_static! {
static ref CACHE: FCache = {
let db: String = cache_path("cache.mdl")
.expect("Fatal error: Can't start the cache");
let mdl_cache = mdl::Cache::new(&db)
.expect("Fatal error: Can't start the cache");
let cache = Arc::new(Mutex::new(mdl_cache));
FCache { cache }
};
}
pub fn get() -> FCache {
return CACHE.clone();
}

5
fractal-gtk/src/main.rs

@ -20,6 +20,7 @@ extern crate failure;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[macro_use]
extern crate fractal_matrix_api as fractal_api;
@ -34,6 +35,10 @@ extern crate chrono;
extern crate fragile;
extern crate mdl;
#[macro_use]
extern crate lazy_static;
use fractal_api::backend;
use fractal_api::types;
use fractal_api::error;

Loading…
Cancel
Save