Scrobbles: use a scalar type filter for latest lookups #8003

Open
lambadalambda wants to merge 4 commits from lambadalambda/pleroma:fix/scrobble-query into develop

Summary

  • Use the existing scalar activity-type filter for scrobble listing, rather than a singleton array filter.
  • Allow the existing actor/type/id index to serve newest-first lookups without changing returned results, account/visibility restrictions, authentication or pagination.
  • Keep the change endpoint-local: one production line, no global query normalization, schema migration or PostgreSQL configuration change.
  • Add a changelog fragment and endpoint regressions for scalar bound SQL, empty results, latest-result selection and account/type isolation.

Verification

TDD: the original three controller tests passed; the new SQL-shape regression failed before the change (five tests, one failure), then controller/view tests passed all six tests.

Using Erlang 28.3 / Elixir 1.19.0:

mix format --check-formatted \
  lib/pleroma/web/pleroma_api/controllers/scrobble_controller.ex \
  test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs

MIX_ENV=test mix test \
  test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs \
  test/pleroma/web/pleroma_api/views/scrobble_view_test.exs \
  test/pleroma/web/activity_pub/activity_pub_test.exs \
  test/pleroma/web/common_api_test.exs

Result: 245 tests, 0 failures, 1 existing skipped test. Formatting and git diff --check pass. Independent correctness/security and architecture review found no blockers.

Read-only query-plan comparisons confirmed that the scalar form can use the existing selective index for a latest-result lookup. No timing-sensitive benchmark or planner-specific index-name assertion is added to CI.

Scope

This PR only changes scrobble lookup query construction. Posting retries/idempotency, traffic controls, migrations and global database settings are unchanged.

## Summary - Use the existing scalar activity-type filter for scrobble listing, rather than a singleton array filter. - Allow the existing actor/type/id index to serve newest-first lookups without changing returned results, account/visibility restrictions, authentication or pagination. - Keep the change endpoint-local: one production line, no global query normalization, schema migration or PostgreSQL configuration change. - Add a changelog fragment and endpoint regressions for scalar bound SQL, empty results, latest-result selection and account/type isolation. ## Verification TDD: the original three controller tests passed; the new SQL-shape regression failed before the change (five tests, one failure), then controller/view tests passed all six tests. Using Erlang 28.3 / Elixir 1.19.0: ```sh mix format --check-formatted \ lib/pleroma/web/pleroma_api/controllers/scrobble_controller.ex \ test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs MIX_ENV=test mix test \ test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs \ test/pleroma/web/pleroma_api/views/scrobble_view_test.exs \ test/pleroma/web/activity_pub/activity_pub_test.exs \ test/pleroma/web/common_api_test.exs ``` Result: **245 tests, 0 failures, 1 existing skipped test**. Formatting and `git diff --check` pass. Independent correctness/security and architecture review found no blockers. Read-only query-plan comparisons confirmed that the scalar form can use the existing selective index for a latest-result lookup. No timing-sensitive benchmark or planner-specific index-name assertion is added to CI. ## Scope This PR only changes scrobble lookup query construction. Posting retries/idempotency, traffic controls, migrations and global database settings are unchanged.
fix(scrobbles): use scalar type filter for latest lookups
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.15 Pipeline was successful
dcfd4d91f1
Merge branch 'develop' into fix/scrobble-query
Some checks failed
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.17 Pipeline was canceled
611a317c01
Author
Owner

/oc review

/oc review
opencode-fix-bot left a comment

opencode-agent:job=147:generation=1

Review: no findings — merge-readiness 5/5

Inspected the complete base-to-head diff (3 files), the downstream query path (ActivityPub.restrict_type/2, fetch_user_abstract_activities/3, Pagination), and the live discussion (no prior reviews). Checked out the exact head and ran the tests on Erlang/OTP 28 + Elixir 1.19.6 against local PostgreSQL.

What the PR does:

  • One production line: the scrobble index now binds :type to 'Listen' instead of ['Listen'], so Ecto emits data->>'type' = $N instead of = ANY($N).
  • restrict_type/2 already has a dedicated is_binary clause producing exactly that scalar predicate, so semantics are unchanged (rows with a missing type are excluded under both forms), and no other consumer of the :type opt in this path assumes a list. The change is endpoint-local; auth, visibility, and pagination are untouched.
  • Changelog fragment follows the repo .fix convention.

Validation performed:

  • mix format --check-formatted on both touched source files: passes.
  • Scrobble controller + view tests: 6 tests, 0 failures.
  • Full set across the four files cited in the PR description: 250 tests, 0 failures, 1 skipped (the skip is pre-existing).
  • Red check: with the production line temporarily reverted to ['Listen'], the new SQL-shape test fails showing data->>'type' = ANY($3); restored to the claimed head, it passes. The telemetry hook is sound: the unauthenticated request path issues exactly one FROM activities query, and ConnCase dispatches in-process so the self()==pid guard holds.

Findings: none. No P0/P1/P2 defects introduced by this PR. (Title is still WIP — authors call on when to undraft.)

opencode-agent:job=147:generation=1 ## Review: no findings — merge-readiness 5/5 Inspected the complete base-to-head diff (3 files), the downstream query path (ActivityPub.restrict_type/2, fetch_user_abstract_activities/3, Pagination), and the live discussion (no prior reviews). Checked out the exact head and ran the tests on Erlang/OTP 28 + Elixir 1.19.6 against local PostgreSQL. What the PR does: - One production line: the scrobble index now binds :type to 'Listen' instead of ['Listen'], so Ecto emits data->>'type' = $N instead of = ANY($N). - restrict_type/2 already has a dedicated is_binary clause producing exactly that scalar predicate, so semantics are unchanged (rows with a missing type are excluded under both forms), and no other consumer of the :type opt in this path assumes a list. The change is endpoint-local; auth, visibility, and pagination are untouched. - Changelog fragment follows the repo .fix convention. Validation performed: - mix format --check-formatted on both touched source files: passes. - Scrobble controller + view tests: 6 tests, 0 failures. - Full set across the four files cited in the PR description: 250 tests, 0 failures, 1 skipped (the skip is pre-existing). - Red check: with the production line temporarily reverted to ['Listen'], the new SQL-shape test fails showing data->>'type' = ANY($3); restored to the claimed head, it passes. The telemetry hook is sound: the unauthenticated request path issues exactly one FROM activities query, and ConnCase dispatches in-process so the self()==pid guard holds. Findings: none. No P0/P1/P2 defects introduced by this PR. (Title is still WIP — authors call on when to undraft.)
Merge branch 'develop' into fix/scrobble-query
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.17 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
195a0c85c0
lambadalambda changed title from WIP: Scrobbles: use a scalar type filter for latest lookups to Scrobbles: use a scalar type filter for latest lookups 2026-11-03 19:13:20 +00:00
Merge branch 'develop' into fix/scrobble-query
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.17 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
4816ad78d7
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.17 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u fix/scrobble-query:lambadalambda-fix/scrobble-query
git switch lambadalambda-fix/scrobble-query

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch develop
git merge --no-ff lambadalambda-fix/scrobble-query
git switch lambadalambda-fix/scrobble-query
git rebase develop
git switch develop
git merge --ff-only lambadalambda-fix/scrobble-query
git switch lambadalambda-fix/scrobble-query
git rebase develop
git switch develop
git merge --no-ff lambadalambda-fix/scrobble-query
git switch develop
git merge --squash lambadalambda-fix/scrobble-query
git switch develop
git merge --ff-only lambadalambda-fix/scrobble-query
git switch develop
git merge lambadalambda-fix/scrobble-query
git push origin develop
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pleroma/pleroma!8003
No description provided.