Skip to content

fix(tasks): reindex users after IP cleanup#556

Open
Samk13 wants to merge 1 commit into
inveniosoftware:masterfrom
Samk13:feat-include-indices-update-in-delete-ip-task
Open

fix(tasks): reindex users after IP cleanup#556
Samk13 wants to merge 1 commit into
inveniosoftware:masterfrom
Samk13:feat-include-indices-update-in-delete-ip-task

Conversation

@Samk13

@Samk13 Samk13 commented Jun 11, 2026

Copy link
Copy Markdown
Member

❤️ Thank you for your contribution!

Description

As requested:

  • Update login IP cleanup to process expired records in batches and bump affected user versions.
  • Mark changed users through the datastore so search indexes stay in sync after IP removal.
  • Cover version updates and datastore change tracking in the IP cleanup task test.

For an easier review, here is how to test the changes:

  1. Seed DB values: see here
    uv run invenio shell scripts/dev/user-check-tools/seed_users_login_info.py

  2. Rebuild user index so DB and OpenSearch start aligned: see here
    uv run invenio shell scripts/indices-migration-v13-14/user-groups-indices-migration.py

  3. Check baseline: see here
    uv run invenio shell scripts/dev/user-check-tools/check_users_login_info_index.py

Run the task with invenio shell

from invenio_accounts.tasks import delete_ips
delete_ips()

run step 3 again and check the difference, or check with curl:

curl --location --request GET 'http://localhost:9200/latest-build-users-user-v3.0.0-*/_search' \
--header 'Content-Type: application/json' \
--data '{
    "_source": ["_index", "_id", "email_hidden", "last_login_ip", "current_login_ip", "current_login_at","last_login_ip"]
}' | jq

Check the screenshot before and after running the script to see the number of users in db and indices should match.

Before and after running the task:

Screenshot 2026-06-11 at 14 36 14

Before

Screenshot 2026-06-11 at 14 34 29

After

Screenshot 2026-06-11 at 14 36 40

Note: This PR includes AI-assisted contributions that have been reviewed, refined, and validated manually.

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Frontend

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

@Samk13 Samk13 requested a review from palkerecsenyi June 11, 2026 13:16
@Samk13 Samk13 force-pushed the feat-include-indices-update-in-delete-ip-task branch from e418808 to 1f758ef Compare June 11, 2026 20:55
Comment thread invenio_accounts/tasks.py
User.updated: db.func.now(),
# User indexing uses version_id as the record revision, so
# bulk changes must advance it to replace the search doc.
User.version_id: User.version_id + 1,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the version_id bump because mark_changed() alone scheduled the reindex, but did not reliably replace the indexed user document.

My main concern is concurrent user updates while this task runs, since bumping version_id can trigger optimistic-lock conflicts for in-flight ORM updates.

If ther's a better way to force user reindexing without touching User.version_id, I'm happy to adjust.

* Update login IP cleanup to process expired records
  in batches and bump affected user versions.
* Mark changed users through the datastore so search
  indexes stay in sync after IP removal.
* Cover version updates and datastore change tracking
  in the IP cleanup task test.
@Samk13 Samk13 force-pushed the feat-include-indices-update-in-delete-ip-task branch from 1f758ef to 2b7e526 Compare June 15, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant