Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist send error state #3806

Merged
merged 4 commits into from
Dec 13, 2018
Merged

Persist send error state #3806

merged 4 commits into from
Dec 13, 2018

Conversation

cketti
Copy link
Member

@cketti cketti commented Dec 8, 2018

This adds the outbox_state table to the database to keep track of the number of send attempts and hard send errors (server declined to send the message as opposed to temporary connection or server error).

It's only a first step towards better send error handling. Nicer notifications, better retry logic, displaying error indicators and actions to perform on messages that failed to send are next steps.

@cketti cketti force-pushed the outbox_state branch 2 times, most recently from 4c3d073 to 818f8fc Compare December 8, 2018 18:05
@@ -229,6 +242,7 @@ private static void dbCreateDatabaseFromScratch(SQLiteDatabase db) {
"BEGIN " +
"DELETE FROM message_parts WHERE root = OLD.message_part_id; " +
"DELETE FROM messages_fulltext WHERE docid = OLD.id; " +
"DELETE FROM outbox_state WHERE message_id = OLD.id; " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason we do this with triggers rather than foreign keys? seems a bit odd. (have I asked this before?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... it seems possible to use foreign keys and CASCADE DELETE in sqlite when using foreign_keys PRAGMA... I didn't know that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course. We use that in OpenKeychain all the time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I see you have foreign keys enabled but I don't see it in K-9 (it isn't used?).

One way or another I think FKs are better approach and the work to enable them would be a good investment anyway :)

Copy link
Member Author

@cketti cketti Dec 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The codebase has never used foreign keys. I believe it's because early Android versions shipped with a Sqlite version that didn't support foreign key constraints.

}

private fun createOutboxStateEntries(db: SQLiteDatabase) {
db.execSQL("INSERT INTO outbox_state (message_id, send_state) " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to avoid """ here?

@@ -41,6 +56,12 @@
private PreviewType previewType;
private boolean headerNeedsUpdating = false;

// Only available for messages in Outbox folder after calling fetchOutboxState()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks pretty ugly to me. could this (and related methods) be kept in an OutboxStateRepository or something? the calls are simple and rare enough that we don't need to worry about caching, plus it would be more easily testable.

@Valodim
Copy link
Contributor

Valodim commented Dec 13, 2018

StoreSchemaDefinition is still using triggers, code-wise lgtm otherwise

@wiktor-k wiktor-k requested review from wiktor-k and removed request for wiktor-k December 13, 2018 19:36
@cketti cketti merged commit ae2f831 into master Dec 13, 2018
@cketti cketti deleted the outbox_state branch December 13, 2018 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants