-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
chat_message_join
can indicate that a single message belongs to multiple chats
#135
Comments
chat_message_join
can indicate that a single message can belong to multiple chatschat_message_join
can indicate that a single message belongs to multiple chats
Using a subquery solves the problem: SELECT
*,
c.chat_id,
(SELECT COUNT(*) FROM message_attachment_join a WHERE m.ROWID = a.message_id) as num_attachments,
(SELECT b.chat_id FROM chat_recoverable_message_join b WHERE m.ROWID = b.message_id) as deleted_from,
(SELECT COUNT(*) FROM message m2 WHERE m2.thread_originator_guid = m.guid) as num_replies
FROM
message as m
LEFT JOIN (SELECT * from chat_message_join GROUP BY message_id) as c ON m.ROWID = c.message_id
ORDER BY
m.date;
However, this comes with a very large performance impact: a normal export (no attachment management, debug build) nosedived from an average rate of |
Since the result set from the query is ordered: imessage-exporter/imessage-database/src/tables/messages.rs Lines 562 to 563 in 102347f
We can just keep track of the last-rendered ROWID and skip rendering if we see the same ID twice. This has negligible performance impact. |
We iterate over the messages table with this query:
imessage-exporter/imessage-database/src/tables/messages.rs
Lines 528 to 581 in 102347f
The query uses a
LEFT JOIN
, so we see one row for each occurrence of a message in thechat_message_join
table.imessage-exporter/imessage-database/src/tables/messages.rs
Line 560 in 102347f
This results in duplicated messages in a conversation, since this software successfully deduplicates chats:
imessage-exporter/imessage-database/src/tables/chat_handle.rs
Lines 88 to 112 in 102347f
In my testing, the only messages that exhibited this were iMessages resent as SMS.
The text was updated successfully, but these errors were encountered: