fix-try 1

This commit is contained in:
holger krekel
2019-09-08 18:40:58 +02:00
parent b32f3f71ad
commit 87c8c5a363

View File

@@ -1711,29 +1711,27 @@ fn search_chat_ids_by_contact_ids(
params![], params![],
|row| Ok((row.get::<_, u32>(0)?, row.get::<_, u32>(1)?)), |row| Ok((row.get::<_, u32>(0)?, row.get::<_, u32>(1)?)),
|rows| { |rows| {
let mut last_chat_id = 0; let mut chat2contacts = HashMap<u32, Vec<u32>>::new();
let mut matches = 0;
let mut mismatches = 0;
for row in rows { for row in rows {
let (chat_id, contact_id) = row?; let (chat_id, contact_id) = row?;
if chat_id != last_chat_id { let mut contacts: Vec<u32>;
if matches == contact_ids.len() && mismatches == 0 { contacts = match chat2contacts.get(chat_id) {
chat_ids.push(last_chat_id); Some(c) => c,
} None => {
last_chat_id = chat_id; l = Vec<u32>::default();
matches = 0; chat2contacts.insert(chat_id, l);
mismatches = 0; l
}
if contact_id == contact_ids[matches] {
matches += 1;
} else {
mismatches += 1;
} }
} }
contacts.push(contact_id);
if matches == contact_ids.len() && mismatches == 0 { }
chat_ids.push(last_chat_id); for (&chat_id, &contacts) in chat2contacts.iter_mut() {
contacts.retain(|x| {
contact_ids.contains(x)
});
if contacts.len() == contact_ids.len() {
chat_ids.push(chat_id)
}
} }
Ok(()) Ok(())
} }