Skip to content

Commit

Permalink
Merge pull request #207 from ReagentX/feat/cs/velvet-ash-fixes
Browse files Browse the repository at this point in the history
Feat/cs/velvet ash fixes
  • Loading branch information
ReagentX authored Nov 23, 2023
2 parents 0a5c6dd + bcc1e85 commit 96c8659
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 31 deletions.
17 changes: 10 additions & 7 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ No, `imessage-exporter` only reads data present on the host system.

#### How does the exporter handle previously exported messages?

If files with the current output type exist in the output directory, `imessage-exporter` will alert the user that they will overwrite existing exported data and the export will be cancelled. If the export directory is clear, `imessage-exporter` will export all messages by default, or between the dates specified by the `--start-date` and `--end-date` arguments.
If files with the current output type exist in the output directory, `imessage-exporter` will alert the user that they will overwrite existing exported data and the export will be cancelled. If the export directory is clear, `imessage-exporter` will export all messages by default. Alternatively, it will export messages between the dates specified by the `--start-date` and `--end-date` arguments.

See [here](../imessage-exporter/README.md#how-to-use) for details on `imessage-exporter` arguments.

Expand Down Expand Up @@ -58,11 +58,14 @@ Messages that have expired from this restoration process are permanently deleted

This is a complicated question that depends on CPU, database size, chosen export type, and chosen attachment handling style.

On my M1 Max MacBook Pro, performance is as follows:
On my M1 Max MacBook Pro, approximate performance is as follows:

- With `--copy-method disabled`, exports run at about `18k` messages per second
- With `--copy-method efficient`, exports run at about `13k` messages per second
- With `--copy-method compatible`, exports run at about `300` messages per second
- For more information on `--copy-method`, see [here](../imessage-exporter/README.md#how-to-use) and [here](./features.md#supported-message-features).
| `--copy-method` | Messages exported per second |
|---|---|
| `disabled` | 18,000 |
| `efficient` | 13,000 |
| `compatible` | 300 |

However, if you recently deleted a large amount of data from Messages, the database will be slow for awhile, and will result in significantly reduced performance from `imessage-exporter`.
For more information on `--copy-method`, see [here](../imessage-exporter/README.md#how-to-use) and [here](./features.md#supported-message-features).

However, if you recently deleted a large amount of data from Messages, the database will be slow for awhile, resulting in significantly reduced performance from `imessage-exporter`.
4 changes: 2 additions & 2 deletions imessage-database/src/error/table.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*!
Errors that can happen when extracting data from a ``SQLite`` table.
Errors that can happen when extracting data from a `SQLite` table.
*/

use std::fmt::{Display, Formatter, Result};

use rusqlite::Error;

/// Errors that can happen when extracting data from a ``SQLite`` table
/// Errors that can happen when extracting data from a `SQLite` table
#[derive(Debug)]
pub enum TableError {
Attachment(Error),
Expand Down
2 changes: 1 addition & 1 deletion imessage-database/src/message_types/variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub enum Variant<'a> {

/// Defines behavior for different types of messages that have custom balloons
pub trait BalloonProvider<'a> {
/// Creates the object from a ``HashMap`` of item attributes
/// Creates the object from a `HashMap` of item attributes
fn from_map(payload: &'a Value) -> Result<Self, PlistParseError>
where
Self: Sized;
Expand Down
2 changes: 1 addition & 1 deletion imessage-database/src/tables/chat_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Table for ChatToHandle {
impl Cacheable for ChatToHandle {
type K = i32;
type V = BTreeSet<i32>;
/// Generate a hashmap containing each chatroom's ID pointing to a ``HashSet`` of participant handle IDs
/// Generate a hashmap containing each chatroom's ID pointing to a `HashSet` of participant handle IDs
///
/// # Example:
///
Expand Down
2 changes: 1 addition & 1 deletion imessage-database/src/tables/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Table for Handle {
impl Cacheable for Handle {
type K = i32;
type V = String;
/// Generate a ``HashMap`` for looking up contacts by their IDs, collapsing
/// Generate a `HashMap` for looking up contacts by their IDs, collapsing
/// duplicate contacts to the same ID String regardless of service
///
/// # Example:
Expand Down
5 changes: 3 additions & 2 deletions imessage-database/src/tables/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ impl Message {
/// let conn = get_connection(&db_path).unwrap();
/// let context = QueryContext::default();
/// Message::stream_rows(&conn, &context).unwrap();
/// ```
pub fn stream_rows<'a>(
db: &'a Connection,
context: &'a QueryContext,
Expand Down Expand Up @@ -658,7 +659,7 @@ impl Message {
}
}

/// Build a ``HashMap`` of message component index to messages that react to that component
/// Build a `HashMap` of message component index to messages that react to that component
pub fn get_reactions(
&self,
db: &Connection,
Expand Down Expand Up @@ -704,7 +705,7 @@ impl Message {
Ok(out_h)
}

/// Build a ``HashMap`` of message component index to messages that reply to that component
/// Build a `HashMap` of message component index to messages that reply to that component
pub fn get_replies(&self, db: &Connection) -> Result<HashMap<usize, Vec<Self>>, TableError> {
let mut out_h: HashMap<usize, Vec<Self>> = HashMap::new();

Expand Down
2 changes: 1 addition & 1 deletion imessage-database/src/tables/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub trait Diagnostic {
fn run_diagnostic(db: &Connection) -> Result<(), TableError>;
}

/// Get a connection to the iMessage ``SQLite`` database
/// Get a connection to the iMessage `SQLite` database
// # Example:
///
/// ```
Expand Down
8 changes: 4 additions & 4 deletions imessage-database/src/util/query_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct QueryContext {
}

impl QueryContext {
/// Generate a ``QueryContext`` with a start date
/// Generate a `QueryContext` with a start date
/// # Example:
///
/// ```
Expand All @@ -34,7 +34,7 @@ impl QueryContext {
Ok(())
}

/// Generate a ``QueryContext`` with an end date
/// Generate a `QueryContext` with an end date
/// # Example:
///
/// ```
Expand Down Expand Up @@ -82,7 +82,7 @@ impl QueryContext {
Some(stamp - (get_offset() * TIMESTAMP_FACTOR))
}

/// Determine if the current ``QueryContext`` has any filters present
/// Determine if the current `QueryContext` has any filters present
///
/// # Example:
///
Expand All @@ -98,7 +98,7 @@ impl QueryContext {
[self.start, self.end].iter().any(Option::is_some)
}

/// Generate the SQL `WHERE` clause described by this ``QueryContext``
/// Generate the SQL `WHERE` clause described by this `QueryContext`
/// # Example:
///
/// ```
Expand Down
2 changes: 1 addition & 1 deletion imessage-exporter/src/app/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl Options {

/// Ensure export path is empty or does not contain files of the existing export type
///
/// We have to allocate a ``PathBuf`` here because it can be created from data owned by this function in the default state
/// We have to allocate a `PathBuf` here because it can be created from data owned by this function in the default state
fn validate_path(
export_path: Option<&String>,
export_type: &Option<&ExportType>,
Expand Down
3 changes: 2 additions & 1 deletion imessage-exporter/src/app/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ impl Config {
get_db_size(&self.options.db_path).map_err(RuntimeError::DatabaseError)?;
let mut estimated_export_size = total_db_size / 10;

let free_space_at_location = available_space(&self.options.export_path).unwrap();
let free_space_at_location =
available_space(&self.options.export_path).map_err(RuntimeError::DiskError)?;

// Validate that there is enough disk space free to write the export
if let AttachmentManager::Disabled = self.options.attachment_manager {
Expand Down
12 changes: 7 additions & 5 deletions imessage-exporter/src/exporters/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<'a> Exporter<'a> for HTML<'a> {

let messages = statement
.query_map([], |row| Ok(Message::from_row(row)))
.unwrap();
.map_err(|err| RuntimeError::DatabaseError(TableError::Messages(err)))?;

for message in messages {
let mut msg = Message::extract(message).map_err(RuntimeError::DatabaseError)?;
Expand All @@ -105,7 +105,7 @@ impl<'a> Exporter<'a> for HTML<'a> {
}
// Message replies and reactions are rendered in context, so no need to render them separately
else if !msg.is_reaction() {
msg.gen_text(&self.config.db);
let _ = msg.gen_text(&self.config.db);
let message = self
.format_message(&msg, 0)
.map_err(RuntimeError::DatabaseError)?;
Expand Down Expand Up @@ -421,7 +421,7 @@ impl<'a> Writer<'a> for HTML<'a> {
replies
.iter_mut()
.try_for_each(|reply| -> Result<(), TableError> {
reply.gen_text(&self.config.db);
let _ = reply.gen_text(&self.config.db);
if !reply.is_reaction() {
// Set indent to 1 so we know this is a recursive call
self.add_line(
Expand Down Expand Up @@ -734,9 +734,11 @@ impl<'a> Writer<'a> for HTML<'a> {

fn write_to_file(file: &Path, text: &str) {
match File::options().append(true).create(true).open(file) {
Ok(mut file) => file.write_all(text.as_bytes()).unwrap(),
Ok(mut file) => {
let _ = file.write_all(text.as_bytes());
}
Err(why) => eprintln!("Unable to write to {file:?}: {why:?}"),
}
};
}
}

Expand Down
12 changes: 7 additions & 5 deletions imessage-exporter/src/exporters/txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<'a> Exporter<'a> for TXT<'a> {

let messages = statement
.query_map([], |row| Ok(Message::from_row(row)))
.unwrap();
.map_err(|err| RuntimeError::DatabaseError(TableError::Messages(err)))?;

for message in messages {
let mut msg = Message::extract(message).map_err(RuntimeError::DatabaseError)?;
Expand All @@ -98,7 +98,7 @@ impl<'a> Exporter<'a> for TXT<'a> {
}
// Message replies and reactions are rendered in context, so no need to render them separately
else if !msg.is_reaction() {
msg.gen_text(&self.config.db);
let _ = msg.gen_text(&self.config.db);
let message = self
.format_message(&msg, 0)
.map_err(RuntimeError::DatabaseError)?;
Expand Down Expand Up @@ -271,7 +271,7 @@ impl<'a> Writer<'a> for TXT<'a> {
replies
.iter_mut()
.try_for_each(|reply| -> Result<(), TableError> {
reply.gen_text(&self.config.db);
let _ = reply.gen_text(&self.config.db);
if !reply.is_reaction() {
self.add_line(
&mut formatted_message,
Expand Down Expand Up @@ -528,9 +528,11 @@ impl<'a> Writer<'a> for TXT<'a> {

fn write_to_file(file: &Path, text: &str) {
match File::options().append(true).create(true).open(file) {
Ok(mut file) => file.write_all(text.as_bytes()).unwrap(),
Ok(mut file) => {
let _ = file.write_all(text.as_bytes());
}
Err(why) => eprintln!("Unable to write to {file:?}: {why:?}"),
}
};
}
}

Expand Down

0 comments on commit 96c8659

Please sign in to comment.