Commit Graph

150 Commits

Author SHA1 Message Date
Harry
74228f424e
Add StoryContextAssociatedData to compute story tab badge count without hidden stories
* Add StoryContextAssociatedData and db migrations

* Remove hideStory from ThreadAssociatedData

* Remove lastViewedStoryTimestamp and lastReceivedStoryTimestamp from TSThread

* drop deprecated columns in db migration

* add indexes

* dump schema.sql

* Update unviewed stories SQL query

* fix thread fetching for incoming story messages

* reload story tab badge when StoryContextAssociatedData changes

* Add test for TSGroupModel backwards-compatible deserialization

* move db migration

* Only use StoryContextAssociatedData for story badge count

* update StoryContextAssociatedData lastReceivedTime when a story message is deleted

* catch group threads for outgoing story messages too

* clean up sql query

* Only update lastReceievedStoryTimestamp for remote deletions

* add latestUnexpiredTimestamp to StoryContextAssociatedData
2022-10-03 21:16:01 -07:00
Evan Hahn
11c2cf0813
Add basic test for database migration
_This change should have no user impact._

This adds a basic test for database migration, and makes the necessary
changes to make that possible.
2022-09-22 17:24:40 +00:00
Evan Hahn
8a13595143 Prompt for diagnostics if db corruption happens
Previously, users who experienced database corruption would be asked to
submit debug logs. (Special builds had additional options which were not
generally available, so some of this code was already written.)

Now, if they choose to submit debug logs, they will also be asked to
submit a "database diagnostic" before the logs are submitted. This runs
and logs the results of `PRAGMA cipher_provider`, `PRAGMA
cipher_integrity_check`, and whether `PRAGMA quick_check` succeeds. If
they choose to skip the diagnostic, we still submit debug logs.

Other launch failures, such as "out of disk space", do not run these
diagnostics, as they're irrelevant.
2022-07-27 11:57:16 -05:00
george-signal
80565fb43f
Revert "Remove GRDB's memory management. (#4521)" (#4546)
This reverts commit a202f6204e.

It also uses the new facility in GRDB to disable
automatic memory management.

For context see:
https://github.com/groue/GRDB.swift/pull/1253
2022-07-11 14:37:29 -07:00
george-signal
a202f6204e
Remove GRDB's memory management. (#4521)
This disgusting hack removes GRDB's notification
center observers, which prevents it from calling
`DatabasePool.releaseMemory()`.

`releaseMemory` is harmful because it places all
future reads behind a dispatch barrier. The effect
is that even very short reads block on any db
reads that precede the barrier. Some of those can
be very slow, such as orphan message handling.

The practical effect of this barrier is that the
main thread gets stuck on what should be a very
quick operation, such as loading your own avatar
data. iOS can kill the app with 8badf00d.

This change is a temporary workaround. A proper
solution has been added to a PR that I sent to
GRDB, which you can see here:

https://github.com/groue/GRDB.swift/pull/1253

Once that is accepted upstream we should update
GRDB and revert this commit.

This change should fix IOS-2474 and doubtless many
other issues.
2022-07-06 13:27:13 -07:00
Evan Hahn
24ca5abf9c Remove unneeded breaks
This fixes our violations of [the SwiftLint `unneeded_break_in_switch`
rule][0].

[0]: https://realm.github.io/SwiftLint/unneeded_break_in_switch.html
2022-06-03 17:52:28 +00:00
Max Radermacher
80e0208bbb
Time out syncTruncatingCheckpoint after 3 seconds 2022-05-17 12:31:03 -07:00
Jordan Rose
7238e957ec Allow running a SQLite integrity check when the app fails to launch
The results are *not* automatically logged in case they contain
sensitive data. (They shouldn't, but we don't control this output
format.)
2022-04-21 09:47:05 -07:00
Evan Hahn
636b417390 Upgrade GRDB to version 5.23.0
This upgrades [GRDB][0] from v4.3.0 to v5.23.0, the latest version.

I closely followed the [migration guide][1] and stole from a prior
attempt at this upgrade. I also made sure to test the media gallery,
because that allegedly had problems before.

[0]: https://github.com/groue/GRDB.swift
[1]: 6d3f309cad/Documentation/GRDB5MigrationGuide.md
2022-04-20 09:08:50 -05:00
Jordan Rose
a61088b76f Add "Export Database" to the internal settings, for debugging 2022-04-18 17:36:42 -07:00
Jordan Rose
49608044b7 SSK: Remove obsolete OWSMessageDecryptJob
This hasn't been used since before GRDB.
2022-04-11 14:46:43 -07:00
Evan Hahn
8b072620a6 Add "Donation Receipts" view 2022-04-11 16:21:12 -05:00
Dimitris Apostolou
62724cf0be Fix typos 2022-03-18 11:31:06 -07:00
Nora Trapp
059dd9a542 Convert TSMention to SDSCodableModel 2022-03-16 18:07:38 -07:00
Nora Trapp
80d1fce505 Convert TSGroupMember to SDSCodableModel 2022-03-16 18:06:59 -07:00
Nora Trapp
91777d5b9f Convert OWSReaction to SDSCodableModel 2022-03-16 18:06:24 -07:00
Nora Trapp
d7f12d3f39 Convert StoryMessageRecord to use new SDSCodableModel 2022-03-16 17:54:38 -07:00
Nora Trapp
5673b73c3a Add HomeTabBarController 2022-03-16 17:52:41 -07:00
Jordan Rose
19f9f6b7cd SSK: Limit the per-database-connection cache in app extensions
The default cache size for a SQLite connection is 2000KiB, but our
database pool has several reader connections plus a writer connection.
They can't share a cache because that changes SQLite's locking model,
so the next best thing is to limit their caches individually when
we're in a memory-constrained environment. To avoid the caches getting
*too* small, this also removes one of the available readers outside
the main app.
2022-02-01 16:39:25 -08:00
Michelle Linington
5f6ee31e68 Most of badge fetching and persistence
Saving progress before running database codegen
2021-11-09 14:25:42 -08:00
Matthew Chen
153095a500 Reduce statics. 2021-11-02 10:36:25 -03:00
Matthew Chen
73594067a0 Reduce GRDB read pool size in NSE. 2021-10-26 15:06:38 -07:00
Michelle Linington
e1241eef76 Fix database path KVO 2021-10-04 09:53:37 -03:00
Michelle Linington
e8d7e7b930 Additional logging 2021-10-04 09:53:37 -03:00
Michelle Linington
6f4d3ea56a Remove debug log messages and lint 2021-10-04 09:53:37 -03:00
Michelle Linington
8446ab4069 Minor changes to folder selection and restoration cleanup 2021-10-04 09:53:36 -03:00
Michelle Linington
417c135fc9 Lint 2021-10-04 09:53:36 -03:00
Michelle Linington
85bdc19dea Better handling of KVO unregistration 2021-10-04 09:53:36 -03:00
Michelle Linington
738a4aae44 Remove ability to open database in other directory modes
This is unsafe in a cross-process world
2021-10-04 09:53:36 -03:00
Michelle Linington
ccf9383533 Improvements to database swap flow
Added a bunch of comments clarifying the database swap requirements.
Also, removed the baseDir parameter from GRDBDatabaseStorageAdapter.
2021-10-04 09:53:36 -03:00
Michelle Linington
fdc983519a Dynaically update database location at runtime
Fixes an issue where users were no longer receiving messages after
restoration. During restoration, the restoring device copies the
transferred database files to a special "hotswap" directory since we
don't want to overwrite our currently in-use database. Once finished, it
re-opens the database pointing to our hotswap directory. It would then
move the hotswap database to its primary location on the next app
launch.

The problem here is our extensions don't know how to read the hotswap
directory. Even if we added that capability, it's going to be tricky to
coordinate which database they read and when as the main app shuffles
files around.

This fix adjusts our restoration flow. Instead of having a special
"primary" and "hotswap" directory that we need to fix up on the next
launch, we instead record a UserDefaults entry that points to our
current database directory.

Once transfer has completed, the main app only needs to update the
current database directory in UserDefaults. No post-launch swapping
needs to occur.

Extensions will listen for updates to this database location by
registering KVO on NSUserDefaults.

This change also adjusts the restoration flow to break it up into
discrete stages. The motivation here is we need to make sure that a
partial restoration doesn't put the extensions in an inconsistent state.
2021-10-04 09:53:35 -03:00
Matthew Chen
e70302ac8f Refine NSE completion blocking, message processing. 2021-09-27 19:04:46 -03:00
Matthew Chen
7356ee90dc Deduplication message decryption to avoid spurious errors when NSE and main app message processing race. 2021-09-22 12:05:28 -07:00
Michelle Linington
51f3a58a61 Message send log recording and resend responses 2021-07-21 22:58:51 -07:00
Matthew Chen
2a0ebc0afe Merge branch 'release/5.16.0' 2021-07-09 15:49:59 -03:00
Matthew Chen
27459a0e2b Respond to CR. 2021-07-09 15:47:10 -03:00
Matthew Chen
587f80969a Fix deadlock crash in DatabaseChangeObserver. 2021-07-09 13:32:19 -03:00
Matthew Chen
89a5dea49b Use file coordinator to protect database creation. 2021-07-08 17:40:45 -03:00
Matthew Chen
d230c45c4c Refine isCheckpointing flag. 2021-07-08 17:35:31 -03:00
Matthew Chen
4f17b816c9 Rework database checkpointing. 2021-07-08 17:35:31 -03:00
Matthew Chen
64309341c6 Rework database checkpointing. 2021-07-08 17:35:31 -03:00
Matthew Chen
a444862311 Rework database checkpointing. 2021-07-08 17:35:31 -03:00
Matthew Chen
6f232977ea Rework database checkpointing. 2021-07-08 17:35:31 -03:00
Matthew Chen
a30400af64 Rework database checkpointing. 2021-07-08 17:35:31 -03:00
Matthew Chen
78fd304b74 Respond to CR. 2021-07-02 22:15:07 -03:00
Matthew Chen
f2b76e60f9 Refine names. 2021-07-02 22:08:53 -03:00
Matthew Chen
103d0d0942 Remove uiRead(). 2021-07-02 22:04:58 -03:00
Matthew Chen
c403dee9c2 Remove uiRead(). 2021-07-02 22:04:58 -03:00
Matthew Chen
f06b72bc2a Remove uiRead(). 2021-07-02 22:04:58 -03:00
Matthew Chen
f65d6e8e2d Remove uiRead(). 2021-07-02 22:04:58 -03:00