imessage_database/tables/diagnostic.rs
1/*!
2 This module contains data structures returned by diagnostic queries on iMessage database tables.
3*/
4
5/// Diagnostic data for the `handle` table
6#[derive(Debug)]
7pub struct HandleDiagnostic {
8 /// The total number of handles in the table
9 pub total_handles: usize,
10 /// The number of distinct `person_centric_id` values in the handle table
11 pub handles_with_multiple_ids: usize,
12 /// The number of handles that were deduplicated into canonical handles
13 pub total_duplicated: usize,
14}
15
16/// Diagnostic data for the `message` table
17#[derive(Debug)]
18pub struct MessageDiagnostic {
19 /// The total number of messages in the table
20 pub total_messages: usize,
21 /// The number of messages not associated with any chat
22 pub messages_without_chat: usize,
23 /// The number of messages that belong to more than one chat
24 pub messages_in_multiple_chats: usize,
25 /// The number of recently deleted messages that are still recoverable
26 pub recoverable_messages: usize,
27 /// The raw `date` value of the earliest message, or `None` if the table is empty
28 pub first_message_date: Option<i64>,
29 /// The raw `date` value of the most recent message, or `None` if the table is empty
30 pub last_message_date: Option<i64>,
31}
32
33/// Diagnostic data for the `attachment` table
34#[derive(Debug)]
35pub struct AttachmentDiagnostic {
36 /// The total number of attachments in the table
37 pub total_attachments: usize,
38 /// The sum of `total_bytes` for all attachments referenced in the table
39 pub total_bytes_referenced: u64,
40 /// The total size of attachment files present on disk
41 pub total_bytes_on_disk: u64,
42 /// The number of attachments with missing files (no path or file not found)
43 pub missing_files: usize,
44 /// The number of attachments with no path provided in the table
45 pub no_path_provided: usize,
46}
47
48impl AttachmentDiagnostic {
49 /// The number of attachments where a path was provided but no file was found at that location
50 #[must_use]
51 pub fn no_file_located(&self) -> usize {
52 self.missing_files.saturating_sub(self.no_path_provided)
53 }
54
55 /// The percentage of attachments that are missing, or `None` if there are no attachments
56 #[must_use]
57 pub fn missing_percent(&self) -> Option<f64> {
58 if self.total_attachments > 0 {
59 Some(self.missing_files as f64 / self.total_attachments as f64 * 100.0)
60 } else {
61 None
62 }
63 }
64}
65
66/// Diagnostic data for chat-handle relationships (thread/chat deduplication)
67#[derive(Debug)]
68pub struct ChatHandleDiagnostic {
69 /// The total number of chats in the table
70 pub total_chats: usize,
71 /// The number of chats that were deduplicated
72 pub total_duplicated: usize,
73 /// The number of chats that have messages but no associated handles
74 pub chats_with_no_handles: usize,
75}