Commit 2896ed4
authored
Add post deletion support to service layer with enhanced stress testing (#1033)
* Add `delete_by_entity_id` to PostRepository and optimize `delete_by_post_id`
Improved post deletion in the repository layer with better performance
and support for entity-based deletion.
Changes:
- Add `delete_by_entity_id` method that accepts an `EntityId` parameter
- Optimize `delete_by_post_id` to remove wasteful full post SELECT query
- `delete_by_entity_id` performs lightweight SELECT for just the post ID, then delegates to `delete_by_post_id`
- All deletion logic now centralized in `delete_by_post_id`
- Add unit tests: `test_repository_delete_by_entity_id` and `test_delete_by_entity_id_deletes_terms` in main test module
- Add constraint test: `test_delete_by_entity_id_non_existent_returns_zero` in posts_constraint_tests.rs
- Both methods automatically clean up associated term relationships
* Add delete methods to PostService with unit tests
Expose post deletion functionality in the service layer for both
entity-based and post ID-based deletion.
Changes:
- Add `delete_by_entity_id` method to `PostService`
- Add `delete_by_post_id` method to `PostService`
- Both methods return `u64` for uniffi compatibility (converts from repository `usize`)
- Both methods automatically clean up associated term relationships via repository layer
- Add comprehensive unit tests: `test_delete_by_entity_id`, `test_delete_by_post_id`, `test_delete_by_entity_id_non_existent_returns_zero`, and `test_delete_by_post_id_non_existent_returns_zero`
- Tests follow consistent pattern: setup via repository/helpers, actions via service layer, verification via repository
* Enhance stress test with delete/insert operations and refactor
Enhanced `start_comprehensive_stress_test` to support random updates,
deletes, and inserts with configurable operation weights. Refactored
for better maintainability and eliminated unnecessary mutations.
Changes:
- Add `StressTestConfig` struct to reduce function parameters from 9 to 3
- Add `StressTestOperation` enum for type-safe operation selection (Update, Delete, Insert)
- Add weighted random operation selection based on configurable weights
- Extract helper functions: `stress_test_batch_update`, `stress_test_batch_delete`, `stress_test_batch_insert`
- Refactor `create_test_post` to accept all parameters (title, slug, link, content)
- Remove `create_temp_post` method in favor of standalone `create_test_post`
- Eliminate mutations when creating new posts (all parameters passed during construction)
- Convert imperative for loops to functional style using `.iter().for_each()`
- Optimize counter increments to batch-level instead of per-item
* Add separate counters for inserts and deletes in stress test
Track and display individual operation counts (updates, inserts, deletes)
in the stress test UI for better observability.
Changes:
- Add `insert_counter` and `delete_counter` to `StressTestHandle` in Rust
- Add `insert_count()` and `delete_count()` methods to expose counters
- Update stress test to increment appropriate counter for each operation type
- Add `totalInserts` and `totalDeletes` StateFlows in Kotlin ViewModel
- Add coroutine to poll operation counters every 100ms from handle
- Update UI to display: "Updates: X | Inserts: Y | Deletes: Z"
- Add "Total Operations" line showing sum of all operations
* make fmt-rust
* Randomize post status during stress test updates
Add status randomization to batch updates, cycling through Draft,
Pending, Publish, and Future statuses to better simulate real-world
database changes.1 parent 84371fa commit 2896ed4
File tree
8 files changed
+555
-125
lines changed- native
- swift
- Example/Example
- Tests/wordpress-api-cache
- wp_mobile_cache/src/repository
- wp_mobile/src/service
8 files changed
+555
-125
lines changedLines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
54 | | - | |
| 56 | + | |
| 57 | + | |
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
| |||
Lines changed: 32 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
42 | 48 | | |
43 | 49 | | |
44 | 50 | | |
| |||
132 | 138 | | |
133 | 139 | | |
134 | 140 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | 141 | | |
139 | 142 | | |
140 | 143 | | |
| |||
145 | 148 | | |
146 | 149 | | |
147 | 150 | | |
| 151 | + | |
148 | 152 | | |
149 | 153 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
154 | 163 | | |
155 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
156 | 177 | | |
157 | 178 | | |
158 | 179 | | |
| |||
203 | 224 | | |
204 | 225 | | |
205 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
206 | 230 | | |
207 | 231 | | |
208 | 232 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
| |||
Lines changed: 9 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
69 | 74 | | |
70 | 75 | | |
71 | 76 | | |
| |||
0 commit comments