1
0
mirror of git://jb55.com/damus synced 2024-09-18 19:23:49 +00:00
damus/damusTests
Daniel D’Aquino 7744787c51 storage: Improve clear cache functionality
This patch improves clear cache functionality by:
- Reducing kingfisher cache removal to one command (The two commands running async was leading to warning logs. One was a subset of the other)
- Removing all files under the cache folder where not currently used by other processes

Full Functionality test
-----------------------

PASS

Device: iPhone 13 mini (Physical device)
iOS: 17.0.3
Damus: This commit
Special remarks:
- I had to locally delete other unit tests to be able to build the test target
- Unit test run on an earlier version of the patch. Test coverage should still apply since this newer patch is a subset of the previous.

Setup: Run Damus with debugger connection to Xcode

Test steps:

1. Follow multiple active accounts (Skip if local Damus is already filled up with GBs of data)
2. Scroll down on the feed for a couple of minutes (or until you have seen at least a few images, a few videos, and link previews) (Skip if local Damus is filled up with GBs of data)
3. In Xcode, download a storage container (Window > Devices and Simulators > Select the device > Select Damus > click on (...) > Download container)
    - Note: Even though you see the file, it does not download instantly. Monitor the file size until it roughly reaches the size reported in iOS storage settings, as the download may still be in progress. This may take a few minutes in some cases.
    - Also take note of storage usage in iOS settings
4. Open the app data package using terminal
5. Run `du -h . | sort -hr`
6. Clear cache and check logs. Logs should indicate the caches being cleared, and there should be no storage-related warning/error logs. PASS
7. Download a new storage container. Remember to wait until it completes download.
8. Run `du -h . | sort -hr` on it.
9. Compare. There should be much less data. Also check iOS settings storage usage. PASS
10. Go back to the home feed and start scrolling, browsing, follow some other people, etc. Look at your own profile as well. Everything should appear to be working as expected with no crashes or important data loss
11. Check bookmarks are still present. PASS
12. Run `DamusCacheManagerTests`. Should pass. PASS* (*See special remarks)

Results:
- Storage usage goes from 3.9GB to 394.7MB
- Damus works as normal after clearing cache, and after restarting the app as well. It becomes slower for a moment, but after a bit it loads as normal again.
- No warning or error logs pertaining to clearing cache
- Unit test passes

My storage container disk usage stats after clearing cache:
```
% du -h | sort -hr
359M	./AppData
359M	.
336M	./AppData/Documents
 23M	./AppData/Library
 20M	./AppData/Library/Caches
7.9M	./AppData/Library/Caches/com.jb55.damus2
2.4M	./AppData/Library/SplashBoard/Snapshots
2.4M	./AppData/Library/SplashBoard
1.8M	./AppData/Library/SplashBoard/Snapshots/com.jb55.damus2 - {DEFAULT GROUP}
1.6M	./AppData/Library/Caches/com.jb55.damus2/fsCachedData
636K	./AppData/Library/SplashBoard/Snapshots/sceneID:com.jb55.damus2-ecc156b1-eb9c-4439-b219-e1eebf2b4c36
596K	./AppData/Library/Caches/com.apple.WebKit.GPU/com.apple.metal
596K	./AppData/Library/Caches/com.apple.WebKit.GPU
452K	./AppData/Library/Caches/com.jb55.damus2/com.apple.metal
296K	./AppData/Library/SplashBoard/Snapshots/sceneID:com.jb55.damus2-ecc156b1-eb9c-4439-b219-e1eebf2b4c36/downscaled
224K	./AppData/Library/HTTPStorages/com.jb55.damus2
224K	./AppData/Library/HTTPStorages
164K	./AppData/Library/Caches/com.onevcat.Kingfisher.ImageCache.default
156K	./AppData/Library/Caches/RelayLogs
112K	./AppData/Library/Caches/com.apple.dyld
 92K	./AppData/Library/Preferences
 60K	./AppData/Library/Caches/com.jb55.damus2/com.apple.metal/archiveUsage.db
 12K	./AppData/Library/Saved Application State/com.jb55.damus2.savedState
 12K	./AppData/Library/Saved Application State
8.0K	./AppData/StoreKit
8.0K	./AppData/Library/Saved Application State/com.jb55.damus2.savedState/ecc156b1-eb9c-4439-b219-e1eebf2b4c36
4.0K	./AppData/Library/Saved Application State/com.jb55.damus2.savedState/KnownSceneSessions
4.0K	./AppData/Library/LanguageModeling/en-dynamic.lm
4.0K	./AppData/Library/LanguageModeling
4.0K	./AppData/Library/Cookies
  0B	./AppData/SystemData/com.apple.SafariViewService/Library/WebKit/WebsiteData
  0B	./AppData/SystemData/com.apple.SafariViewService/Library/WebKit
  0B	./AppData/SystemData/com.apple.SafariViewService/Library
  0B	./AppData/SystemData/com.apple.SafariViewService
```

Biggest storage used remaining is in the Documents folder where NostrDB is stored. However, we do not want to clear NostrDB, so this is expected behavior.

Changelog-Changed: Improve clear cache functionality
Closes: https://github.com/damus-io/damus/issues/1472
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-07 16:42:08 -07:00
..
Models Create helper extensions for Block and update tests for the Block helper model 2023-09-03 18:02:32 -07:00
Util test: add text attribute testing function 2023-07-17 10:25:09 -07:00
Bech32Tests.swift ndb: switch to nostrdb notes 2023-08-03 13:20:36 -07:00
ContentParserTests.swift content: add utf8 char at url left boundary test 2023-07-16 11:46:23 -07:00
DamusCacheManagerTests.swift storage: Improve clear cache functionality 2023-10-07 16:42:08 -07:00
damusTests.swift Properly implement top-level tests and fix one test using the wrong Block conversion property 2023-09-03 18:02:32 -07:00
DMTests.swift Fix old notifications always appearing on first start 2023-08-06 09:22:28 -07:00
EventGroupViewTests.swift tests: add ndb support to tests 2023-09-21 09:10:06 -04:00
FormatTests.swift Fix localization issues, add tests, import translations, and add zh-CN and zh-TW 2023-02-24 12:44:54 -08:00
HashtagTests.swift test: add test cases for ASCII and UTF-8 characters in hashtags 2023-09-15 12:31:17 -05:00
InvoiceTests.swift Create helper extensions for Block and update tests for the Block helper model 2023-09-03 18:02:32 -07:00
KeychainStorageTests.swift Replace Vault dependency with @KeychainStorage property wrapper 2023-05-04 15:57:02 -07:00
LikeTests.swift ndb: switch to nostrdb notes 2023-08-03 13:20:36 -07:00
ListTests.swift ndb: switch to nostrdb notes 2023-08-03 13:20:36 -07:00
LocalizationUtilTests.swift Fix localization issues and export strings for translation 2023-07-14 09:34:29 -07:00
LongPostTests.swift tests: add ndb support to tests 2023-09-21 09:10:06 -04:00
NIP19Tests.swift ndb: switch to nostrdb notes 2023-08-03 13:20:36 -07:00
NostrEventTests.swift Fix image links appearing with escaped slashes 2023-08-18 08:41:21 -07:00
NostrScriptTests.swift nostrdb: add profiles to nostrdb 2023-09-21 09:10:06 -04:00
NoteContentViewTests.swift tests: add ndb support to tests 2023-09-21 09:10:06 -04:00
PostViewTests.swift Fix text editing issues on characters added right after mention link 2023-08-20 17:25:06 -07:00
ProfileViewTests.swift tests: add ndb support to tests 2023-09-21 09:10:06 -04:00
ReplyDescriptionTests.swift Add image uploader 2023-03-15 17:12:05 -06:00
ReplyTests.swift Properly implement top-level tests and fix one test using the wrong Block conversion property 2023-09-03 18:02:32 -07:00
RequestTests.swift tests: disable invalid tests 2023-06-23 20:46:27 +02:00
TimeAgoTests.swift Fix localization issues, add tests, import translations, and add zh-CN and zh-TW 2023-02-24 12:44:54 -08:00
TrieTests.swift Add trie-based user search cache to replace non-performant linear scans 2023-07-03 12:06:01 -07:00
UrlTests.swift Create helper extensions for Block and update tests for the Block helper model 2023-09-03 18:02:32 -07:00
UserSearchAppendTests.swift posting: fix issue with username and multiple emojis 2023-09-11 07:48:36 -07:00
UserSearchCacheTests.swift test: temporarily disable UserCacheManagerTests 2023-10-07 14:35:24 -07:00
WalletConnectTests.swift nostrdb: add profiles to nostrdb 2023-09-21 09:10:06 -04:00
ZapTests.swift test: temporarily disable UserCacheManagerTests 2023-10-07 14:35:24 -07:00