Skip to content

Conversation

@oguzkocer
Copy link
Contributor

Overview

Adds post deletion functionality throughout the stack (repository → service → stress test) with optimized database queries and comprehensive observability.

Changes

Repository Layer

  • Add delete_by_entity_id method that performs lightweight SELECT for post ID then delegates deletion
  • Optimize delete_by_post_id by removing wasteful full post SELECT (0 queries when deleting by post ID)
  • Centralize all deletion logic in delete_by_post_id for consistency
  • Automatically clean up term relationships during deletion
  • Add unit tests in both main test module and constraint tests

Service Layer

  • Expose delete_by_entity_id and delete_by_post_id methods in PostService
  • Return u64 instead of usize for uniffi compatibility
  • Add 4 comprehensive unit tests following consistent patterns (setup via repository, actions via service, verification via repository)

Stress Test Enhancements

  • Extend start_comprehensive_stress_test to support updates, deletes, and inserts with configurable operation weights
  • Introduce StressTestConfig struct to reduce function parameters from 9 to 3
  • Add StressTestOperation enum for type-safe operation selection
  • Extract helper functions for each operation type and convert to functional programming style (.iter().for_each())
  • Eliminate mutations when creating new posts (all parameters passed during construction)
  • Add separate counters (insert_counter, delete_counter) to StressTestHandle for observability

Kotlin Example App

  • Update UI to display individual operation counts: "Updates: X | Inserts: Y | Deletes: Z"
  • Add coroutine to poll operation counters every 100ms
  • Display total operations count for at-a-glance monitoring

…ost_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
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
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
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
@oguzkocer oguzkocer added this to the 0.2 milestone Nov 24, 2025
@oguzkocer oguzkocer requested a review from jkmassel November 24, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants