fix(location): do not sql recurse in location sending

This commit is contained in:
dignifiedquire
2019-09-11 17:46:05 +02:00
parent 68b5e34fed
commit 64b00fce7d

View File

@@ -548,9 +548,7 @@ pub fn job_do_DC_JOB_MAYBE_SEND_LOCATIONS(context: &Context, _job: &Job) {
" ----------------- MAYBE_SEND_LOCATIONS -------------- ", " ----------------- MAYBE_SEND_LOCATIONS -------------- ",
); );
context if let Ok(rows) = context.sql.query_map(
.sql
.query_map(
"SELECT id, locations_send_begin, locations_last_sent \ "SELECT id, locations_send_begin, locations_last_sent \
FROM chats \ FROM chats \
WHERE locations_send_until>?;", WHERE locations_send_until>?;",
@@ -569,7 +567,14 @@ pub fn job_do_DC_JOB_MAYBE_SEND_LOCATIONS(context: &Context, _job: &Job) {
} }
}, },
|rows| { |rows| {
context.sql.prepare( rows.filter_map(|v| v.transpose())
.collect::<Result<Vec<_>, _>>()
.map_err(Into::into)
},
) {
context
.sql
.prepare(
"SELECT id \ "SELECT id \
FROM locations \ FROM locations \
WHERE from_id=? \ WHERE from_id=? \
@@ -578,13 +583,7 @@ pub fn job_do_DC_JOB_MAYBE_SEND_LOCATIONS(context: &Context, _job: &Job) {
AND independent=0 \ AND independent=0 \
ORDER BY timestamp;", ORDER BY timestamp;",
|mut stmt_locations, _| { |mut stmt_locations, _| {
for (chat_id, locations_send_begin, locations_last_sent) in for (chat_id, locations_send_begin, locations_last_sent) in rows {
rows.filter_map(|r| match r {
Ok(Some(v)) => Some(v),
_ => None,
})
{
// TODO: do I need to reset?
if !stmt_locations if !stmt_locations
.exists(params![1, locations_send_begin, locations_last_sent,]) .exists(params![1, locations_send_begin, locations_last_sent,])
.unwrap_or_default() .unwrap_or_default()
@@ -611,10 +610,8 @@ pub fn job_do_DC_JOB_MAYBE_SEND_LOCATIONS(context: &Context, _job: &Job) {
Ok(()) Ok(())
}, },
) )
},
)
.unwrap(); // TODO: Better error handling .unwrap(); // TODO: Better error handling
}
if 0 != continue_streaming { if 0 != continue_streaming {
schedule_MAYBE_SEND_LOCATIONS(context, 0x1); schedule_MAYBE_SEND_LOCATIONS(context, 0x1);
} }