Update cached count for "done" todos when deleting todo targets
What does this MR do?
Previously we were only considering users with "pending" todos, which led to a display bug where we show a wrong count for "done" todos.
Fixes #327110 (closed), follow-up from #325690 (closed).
Query plans
Previous query:
SELECT "users".* FROM "users" WHERE "users"."id" IN (SELECT "todos"."user_id" FROM "todos" WHERE "todos"."target_id" = 1 AND "todos"."target_type" = 'Issue' AND ("todos"."state" IN ('pending')))
- cold cache: 9.187 ms https://console.postgres.ai/shared/63c3f22c-260c-4e2f-979c-8c81129079ea
- warm cache: 1.348 ms https://console.postgres.ai/shared/33c7c210-c0d1-4951-be3d-6a77668feb5b
New query:
SELECT "users".* FROM "users" WHERE "users"."id" IN (SELECT DISTINCT "todos"."user_id" FROM "todos" WHERE "todos"."target_id" = 1 AND "todos"."target_type" = 'Issue')
- cold cache: 8.988 ms https://console.postgres.ai/shared/63fb2ccd-16f1-4ffe-9f47-e0f89b3d4b19
- warm cache: 1.183 ms https://console.postgres.ai/shared/430e7123-2359-4e62-86fa-a7b155b437c1
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?-
I have included a changelog entry.
-
- [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides - [-] Database guides
- [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
- [-] Label as security and @ mention
@gitlab-com/gl-security/appsec
- [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
- [-] Security reports checked/validated by a reviewer from the AppSec team
Related to #327110 (closed)
Edited by Markus Koller