Update deps

This commit is contained in:
Jan Alexander Steffens (heftig)
2020-02-14 15:36:31 +01:00
parent 0c8e657ec0
commit 39750c763e
3 changed files with 593 additions and 532 deletions

1079
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,14 +6,13 @@ version = "0.1.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
clap = "2.32.0" clap = "2.33.0"
fallible-iterator = "0.1.5" indicatif = "0.14.0"
indicatif = "0.11.0" jemallocator = "0.3.2"
jemallocator = "0.3.0" postgres = "0.17.0"
postgres = "0.15.2" rand = "0.7.2"
rand = "0.7.0" rayon = "1.3.0"
rayon = "1.0.2" string_cache = "0.8.0"
string_cache = "0.7.3"
[dependencies.state-map] [dependencies.state-map]
git = "https://github.com/matrix-org/rust-matrix-state-map" git = "https://github.com/matrix-org/rust-matrix-state-map"

View File

@@ -12,11 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use fallible_iterator::FallibleIterator;
use indicatif::{ProgressBar, ProgressStyle}; use indicatif::{ProgressBar, ProgressStyle};
use postgres::{Connection, TlsMode}; use postgres::{fallible_iterator::FallibleIterator, Client};
use rand::{distributions::Alphanumeric, thread_rng, Rng}; use rand::{distributions::Alphanumeric, thread_rng, Rng};
use std::{borrow::Cow, collections::BTreeMap, fmt}; use std::{borrow::Cow, collections::BTreeMap, fmt, iter};
use super::StateGroupEntry; use super::StateGroupEntry;
@@ -27,9 +26,9 @@ pub fn get_data_from_db(
room_id: &str, room_id: &str,
max_state_group: Option<i64>, max_state_group: Option<i64>,
) -> BTreeMap<i64, StateGroupEntry> { ) -> BTreeMap<i64, StateGroupEntry> {
let conn = Connection::connect(db_url, TlsMode::None).unwrap(); let mut client = Client::connect(db_url, postgres::NoTls).unwrap();
let mut state_group_map = get_initial_data_from_db(&conn, room_id, max_state_group); let mut state_group_map = get_initial_data_from_db(&mut client, room_id, max_state_group);
println!("Got initial state from database. Checking for any missing state groups..."); println!("Got initial state from database. Checking for any missing state groups...");
@@ -64,7 +63,7 @@ pub fn get_data_from_db(
println!("Missing {} state groups", missing_sgs.len()); println!("Missing {} state groups", missing_sgs.len());
let map = get_missing_from_db(&conn, &missing_sgs); let map = get_missing_from_db(&mut client, &missing_sgs);
state_group_map.extend(map.into_iter()); state_group_map.extend(map.into_iter());
} }
@@ -74,7 +73,7 @@ pub fn get_data_from_db(
/// Fetch the entries in state_groups_state (and their prev groups) for the /// Fetch the entries in state_groups_state (and their prev groups) for the
/// given `room_id` by fetching all state with the given `room_id`. /// given `room_id` by fetching all state with the given `room_id`.
fn get_initial_data_from_db( fn get_initial_data_from_db(
conn: &Connection, client: &mut Client,
room_id: &str, room_id: &str,
max_state_group: Option<i64>, max_state_group: Option<i64>,
) -> BTreeMap<i64, StateGroupEntry> { ) -> BTreeMap<i64, StateGroupEntry> {
@@ -93,14 +92,10 @@ fn get_initial_data_from_db(
} }
); );
let stmt = conn.prepare(&sql).unwrap();
let trans = conn.transaction().unwrap();
let mut rows = if let Some(s) = max_state_group { let mut rows = if let Some(s) = max_state_group {
stmt.lazy_query(&trans, &[&room_id, &s], 1000) client.query_raw(&sql[..], vec![&room_id as _, &s as _])
} else { } else {
stmt.lazy_query(&trans, &[&room_id], 1000) client.query_raw(&sql[..], iter::once(&room_id as _))
} }
.unwrap(); .unwrap();
@@ -140,19 +135,17 @@ fn get_initial_data_from_db(
} }
/// Get any missing state groups from the database /// Get any missing state groups from the database
fn get_missing_from_db(conn: &Connection, missing_sgs: &[i64]) -> BTreeMap<i64, StateGroupEntry> { fn get_missing_from_db(client: &mut Client, missing_sgs: &[i64]) -> BTreeMap<i64, StateGroupEntry> {
let stmt = conn let mut rows = client
.prepare( .query_raw(
r#" r#"
SELECT state_group, prev_state_group SELECT state_group, prev_state_group
FROM state_group_edges FROM state_group_edges
WHERE state_group = ANY($1) WHERE state_group = ANY($1)
"#, "#,
iter::once(&missing_sgs as _),
) )
.unwrap(); .unwrap();
let trans = conn.transaction().unwrap();
let mut rows = stmt.lazy_query(&trans, &[&missing_sgs], 100).unwrap();
// initialise the map with empty entries (the missing group may not // initialise the map with empty entries (the missing group may not
// have a prev_state_group either) // have a prev_state_group either)