Commit 9fbfdac
committed
Replace per-conversation expiration timers with single next-expiration timer (#509)
## Summary
Replaces the per-conversation `Task.sleep` timers added in #475 with a proper single-timer architecture in `ExpiredConversationsWorker`.
## Problem
PR #475 added per-conversation `Task.sleep` tasks in `ScheduledExplosionManager` to detect when conversations expire while the app is foregrounded. This approach had several issues:
1. **Wrong responsibility** — `ScheduledExplosionManager` handles local push notifications. Expiration cleanup belongs in `ExpiredConversationsWorker`.
2. **Per-conversation tasks don't scale** — 10 scheduled explosions = 10 sleeping tasks.
3. **Duplicates existing logic** — `ExpiredConversationsWorker` already knows how to query and clean up expired conversations, it just needed a trigger.
## Solution
`ExpiredConversationsWorker` now maintains a **single timer** for the next expiring conversation:
1. After processing expired conversations, queries DB for the soonest future `expiresAt`
2. Schedules one `Task.sleep` for that duration
3. When the timer fires, processes all newly-expired conversations and reschedules
The timer is cancelled and rescheduled whenever:
- A new explosion is scheduled (`.conversationScheduledExplosion`)
- The app becomes active (`didBecomeActive`)
- A conversation expires (`.conversationExpired`)
## Changes
- **`ScheduledExplosionManager`**: Removed all expiration task logic (`_expirationTasks`, `scheduleExpirationTask`, `postConversationExpired`). Now only handles local push notification scheduling.
- **`ExpiredConversationsWorker`**: Added single `nextExpirationTask` timer with `fetchNextExpiration()` DB query. Now also observes `.conversationScheduledExplosion`.
- **Tests**: Moved expiration tests to new `ExpiredConversationsWorkerTests`. All existing `ScheduledExplosionManager` notification tests still pass.
Stacks on #475.
<!-- Macroscope's pull request summary starts here -->
<!-- Macroscope will only edit the content between these invisible markers, and the markers themselves will not be visible in the GitHub rendered markdown. -->
<!-- If you delete either of the start / end markers from your PR's description, Macroscope will append its summary at the bottom of the description. -->
> [!NOTE]
> ### Replace per-conversation expiration timers with a single buffered next-expiration Task in `ExpiredConversationsWorker.scheduleNextExpirationCheck` with a 0.5s wake buffer
> Move expiration timing from `ScheduledExplosionManager` to `ExpiredConversationsWorker`, add `checkAndReschedule` and a single `nextExpirationTask`, and gate progress indicator completion animation via `HoldToConfirmStyleConfig.poofProgressIndicatorOnComplete`.
>
> #### 📍Where to Start
> Start with `ExpiredConversationsWorker.checkAndReschedule` in [ExpiredConversationsWorker.swift](https://github.com/xmtplabs/convos-ios/pull/509/files#diff-0fe27ce7c3c36513ccb0460c6a57e998999c277b68bf21f48fbf24d6b935a616).
>
> <!-- Macroscope's review summary starts here -->
>
> <sup><a href="https://app.macroscope.com">Macroscope</a> summarized 6fd1648.</sup>
> <!-- Macroscope's review summary ends here -->
>
<!-- macroscope-ui-refresh -->
<!-- Macroscope's pull request summary ends here -->1 parent db88524 commit 9fbfdac
5 files changed
Lines changed: 338 additions & 130 deletions
File tree
- ConvosCore
- Sources/ConvosCore/Storage/Workers
- Tests/ConvosCoreTests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
68 | 73 | | |
69 | 74 | | |
70 | 75 | | |
| |||
96 | 101 | | |
97 | 102 | | |
98 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
99 | 108 | | |
100 | 109 | | |
101 | 110 | | |
| |||
Lines changed: 93 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
6 | 12 | | |
7 | | - | |
8 | | - | |
9 | | - | |
| 13 | + | |
| 14 | + | |
10 | 15 | | |
11 | 16 | | |
12 | 17 | | |
13 | 18 | | |
14 | 19 | | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
| |||
22 | 29 | | |
23 | 30 | | |
24 | 31 | | |
25 | | - | |
| 32 | + | |
26 | 33 | | |
27 | 34 | | |
28 | 35 | | |
29 | 36 | | |
30 | 37 | | |
| 38 | + | |
31 | 39 | | |
32 | 40 | | |
33 | 41 | | |
| |||
38 | 46 | | |
39 | 47 | | |
40 | 48 | | |
41 | | - | |
| 49 | + | |
42 | 50 | | |
43 | 51 | | |
44 | 52 | | |
| |||
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
53 | | - | |
| 61 | + | |
54 | 62 | | |
55 | 63 | | |
56 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
57 | 73 | | |
58 | 74 | | |
59 | 75 | | |
60 | 76 | | |
61 | 77 | | |
62 | | - | |
| 78 | + | |
63 | 79 | | |
64 | 80 | | |
65 | 81 | | |
66 | | - | |
| 82 | + | |
67 | 83 | | |
68 | 84 | | |
69 | | - | |
| 85 | + | |
| 86 | + | |
70 | 87 | | |
71 | 88 | | |
72 | 89 | | |
73 | | - | |
| 90 | + | |
74 | 91 | | |
75 | 92 | | |
76 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
77 | 127 | | |
78 | 128 | | |
79 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
80 | 144 | | |
81 | 145 | | |
82 | 146 | | |
83 | | - | |
84 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
85 | 150 | | |
86 | 151 | | |
87 | 152 | | |
| |||
104 | 169 | | |
105 | 170 | | |
106 | 171 | | |
107 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
108 | 175 | | |
109 | 176 | | |
110 | 177 | | |
111 | 178 | | |
112 | 179 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 180 | + | |
| 181 | + | |
117 | 182 | | |
118 | 183 | | |
119 | 184 | | |
| |||
139 | 204 | | |
140 | 205 | | |
141 | 206 | | |
142 | | - | |
| 207 | + | |
143 | 208 | | |
144 | 209 | | |
145 | 210 | | |
| |||
154 | 219 | | |
155 | 220 | | |
156 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
157 | 231 | | |
Lines changed: 2 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
| 9 | + | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
88 | | - | |
89 | | - | |
90 | 87 | | |
91 | 88 | | |
92 | 89 | | |
| |||
95 | 92 | | |
96 | 93 | | |
97 | 94 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | 95 | | |
135 | 96 | | |
136 | 97 | | |
| |||
182 | 143 | | |
183 | 144 | | |
184 | 145 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | 146 | | |
190 | 147 | | |
191 | 148 | | |
| |||
199 | 156 | | |
200 | 157 | | |
201 | 158 | | |
202 | | - | |
203 | 159 | | |
204 | 160 | | |
205 | 161 | | |
| |||
297 | 253 | | |
298 | 254 | | |
299 | 255 | | |
300 | | - | |
301 | 256 | | |
302 | | - | |
303 | 257 | | |
304 | 258 | | |
305 | 259 | | |
306 | 260 | | |
307 | 261 | | |
308 | 262 | | |
309 | 263 | | |
310 | | - | |
311 | | - | |
312 | 264 | | |
313 | 265 | | |
314 | 266 | | |
| |||
0 commit comments