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