mirror of
https://github.com/chatmail/core.git
synced 2026-04-02 05:22:14 +03:00
(dig,hpk) pull out job collection from sql query/lock logic
This commit is contained in:
116
src/dc_chat.rs
116
src/dc_chat.rs
@@ -1962,7 +1962,7 @@ pub unsafe fn dc_forward_msgs(
|
||||
curr_timestamp = dc_create_smeared_timestamps(context, msg_cnt);
|
||||
idsstr = dc_arr_to_string(msg_ids, msg_cnt);
|
||||
|
||||
context
|
||||
let ids = context
|
||||
.sql
|
||||
.query_map(
|
||||
format!(
|
||||
@@ -1972,63 +1972,63 @@ pub unsafe fn dc_forward_msgs(
|
||||
params![],
|
||||
|row| row.get::<_, i32>(0),
|
||||
|ids| {
|
||||
for id in ids {
|
||||
let src_msg_id = id?;
|
||||
if !dc_msg_load_from_db(msg, context, src_msg_id as u32) {
|
||||
break;
|
||||
}
|
||||
dc_param_set_packed(original_param, (*(*msg).param).packed);
|
||||
if (*msg).from_id != 1i32 as libc::c_uint {
|
||||
dc_param_set_int((*msg).param, 'a' as i32, 1i32);
|
||||
}
|
||||
dc_param_set((*msg).param, 'c' as i32, 0 as *const libc::c_char);
|
||||
dc_param_set((*msg).param, 'u' as i32, 0 as *const libc::c_char);
|
||||
dc_param_set((*msg).param, 'S' as i32, 0 as *const libc::c_char);
|
||||
let new_msg_id: uint32_t;
|
||||
if (*msg).state == 18i32 {
|
||||
let fresh9 = curr_timestamp;
|
||||
curr_timestamp = curr_timestamp + 1;
|
||||
new_msg_id = prepare_msg_raw(context, chat, msg, fresh9);
|
||||
let save_param: *mut dc_param_t = (*msg).param;
|
||||
(*msg).param = original_param;
|
||||
(*msg).id = src_msg_id as uint32_t;
|
||||
let old_fwd: *mut libc::c_char = dc_param_get(
|
||||
(*msg).param,
|
||||
'P' as i32,
|
||||
b"\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
let new_fwd: *mut libc::c_char = dc_mprintf(
|
||||
b"%s %d\x00" as *const u8 as *const libc::c_char,
|
||||
old_fwd,
|
||||
new_msg_id,
|
||||
);
|
||||
dc_param_set((*msg).param, 'P' as i32, new_fwd);
|
||||
dc_msg_save_param_to_disk(msg);
|
||||
free(new_fwd as *mut libc::c_void);
|
||||
free(old_fwd as *mut libc::c_void);
|
||||
(*msg).param = save_param
|
||||
} else {
|
||||
(*msg).state = 20i32;
|
||||
let fresh10 = curr_timestamp;
|
||||
curr_timestamp = curr_timestamp + 1;
|
||||
new_msg_id = prepare_msg_raw(context, chat, msg, fresh10);
|
||||
dc_job_send_msg(context, new_msg_id);
|
||||
}
|
||||
carray_add(
|
||||
created_db_entries,
|
||||
chat_id as uintptr_t as *mut libc::c_void,
|
||||
0 as *mut libc::c_uint,
|
||||
);
|
||||
carray_add(
|
||||
created_db_entries,
|
||||
new_msg_id as uintptr_t as *mut libc::c_void,
|
||||
0 as *mut libc::c_uint,
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
.unwrap(); // TODO: better error handling
|
||||
ids.collect::<Result<Vec<_>, _>>().map_err(Into::into)
|
||||
}
|
||||
);
|
||||
|
||||
for id in ids.unwrap() {
|
||||
let src_msg_id = id;
|
||||
if !dc_msg_load_from_db(msg, context, src_msg_id as u32) {
|
||||
break;
|
||||
}
|
||||
dc_param_set_packed(original_param, (*(*msg).param).packed);
|
||||
if (*msg).from_id != 1i32 as libc::c_uint {
|
||||
dc_param_set_int((*msg).param, 'a' as i32, 1i32);
|
||||
}
|
||||
dc_param_set((*msg).param, 'c' as i32, 0 as *const libc::c_char);
|
||||
dc_param_set((*msg).param, 'u' as i32, 0 as *const libc::c_char);
|
||||
dc_param_set((*msg).param, 'S' as i32, 0 as *const libc::c_char);
|
||||
let new_msg_id: uint32_t;
|
||||
if (*msg).state == 18i32 {
|
||||
let fresh9 = curr_timestamp;
|
||||
curr_timestamp = curr_timestamp + 1;
|
||||
new_msg_id = prepare_msg_raw(context, chat, msg, fresh9);
|
||||
let save_param: *mut dc_param_t = (*msg).param;
|
||||
(*msg).param = original_param;
|
||||
(*msg).id = src_msg_id as uint32_t;
|
||||
let old_fwd: *mut libc::c_char = dc_param_get(
|
||||
(*msg).param,
|
||||
'P' as i32,
|
||||
b"\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
let new_fwd: *mut libc::c_char = dc_mprintf(
|
||||
b"%s %d\x00" as *const u8 as *const libc::c_char,
|
||||
old_fwd,
|
||||
new_msg_id,
|
||||
);
|
||||
dc_param_set((*msg).param, 'P' as i32, new_fwd);
|
||||
dc_msg_save_param_to_disk(msg);
|
||||
free(new_fwd as *mut libc::c_void);
|
||||
free(old_fwd as *mut libc::c_void);
|
||||
(*msg).param = save_param
|
||||
} else {
|
||||
(*msg).state = 20i32;
|
||||
let fresh10 = curr_timestamp;
|
||||
curr_timestamp = curr_timestamp + 1;
|
||||
new_msg_id = prepare_msg_raw(context, chat, msg, fresh10);
|
||||
dc_job_send_msg(context, new_msg_id);
|
||||
}
|
||||
carray_add(
|
||||
created_db_entries,
|
||||
chat_id as uintptr_t as *mut libc::c_void,
|
||||
0 as *mut libc::c_uint,
|
||||
);
|
||||
carray_add(
|
||||
created_db_entries,
|
||||
new_msg_id as uintptr_t as *mut libc::c_void,
|
||||
0 as *mut libc::c_uint,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if !created_db_entries.is_null() {
|
||||
|
||||
@@ -80,12 +80,14 @@ unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network:
|
||||
params_probe
|
||||
};
|
||||
|
||||
let jobs: Vec<dc_job_t> = context
|
||||
info!(context, 0, "dc_job_perform before query");
|
||||
let jobs: Result<Vec<dc_job_t>,_> = context
|
||||
.sql
|
||||
.query_map(
|
||||
query,
|
||||
params,
|
||||
|row| {
|
||||
info!(context, 0, "START jobs query_maps");
|
||||
let job = dc_job_t {
|
||||
job_id: row.get(0)?,
|
||||
action: row.get(1)?,
|
||||
@@ -100,16 +102,22 @@ unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network:
|
||||
|
||||
let packed: String = row.get(3)?;
|
||||
dc_param_set_packed(job.param, to_cstring(packed).as_ptr());
|
||||
info!(context, 0, "DONE jobs query_maps row");
|
||||
Ok(job)
|
||||
},
|
||||
|jobs| {
|
||||
jobs.collect::<Result<Vec<dc_job_t>, _>>()
|
||||
.map_err(Into::into)
|
||||
info!(context, 0, "collecting jobs");
|
||||
let res = jobs.collect::<Result<Vec<dc_job_t>, _>>()
|
||||
.map_err(Into::into);
|
||||
info!(context, 0, "collecting jobs done");
|
||||
res
|
||||
},
|
||||
)
|
||||
.unwrap_or_default();
|
||||
|
||||
for mut job in jobs {
|
||||
);
|
||||
match jobs {
|
||||
Ok(ref res) => {info!(context, 0, "query done, {:?}", res.len()); },
|
||||
Err(ref err) => {info!(context, 0, "query failed: {:?}", err); }
|
||||
}
|
||||
for mut job in jobs.unwrap_or_default() {
|
||||
info!(
|
||||
context,
|
||||
0,
|
||||
|
||||
30
src/imap.rs
30
src/imap.rs
@@ -471,24 +471,9 @@ impl Imap {
|
||||
fn unsetup_handle(&self, context: &Context) {
|
||||
info!(context, 0, "IMAP unsetup_handle starts");
|
||||
|
||||
// XXX the next line currently can block even if all threads
|
||||
// terminated already
|
||||
let session = self.session.lock().unwrap().take();
|
||||
info!(
|
||||
context,
|
||||
0, "IMAP unsetup_handle step1 (acquired session.lock)"
|
||||
);
|
||||
if session.is_some() {
|
||||
match session.unwrap().close() {
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
eprintln!("failed to close connection: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
info!(
|
||||
context,
|
||||
0, "IMAP unsetup_handle step 2 (closing down stream)."
|
||||
0, "IMAP unsetup_handle step 1 (closing down stream)."
|
||||
);
|
||||
let stream = self.stream.write().unwrap().take();
|
||||
if stream.is_some() {
|
||||
@@ -499,6 +484,19 @@ impl Imap {
|
||||
}
|
||||
}
|
||||
}
|
||||
info!(
|
||||
context,
|
||||
0, "IMAP unsetup_handle step 2 (acquired session.lock)"
|
||||
);
|
||||
let session = self.session.lock().unwrap().take();
|
||||
if session.is_some() {
|
||||
match session.unwrap().close() {
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
eprintln!("failed to close connection: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
info!(context, 0, "IMAP unsetup_handle step 3 (clearing config).");
|
||||
self.config.write().unwrap().selected_folder = None;
|
||||
|
||||
Reference in New Issue
Block a user