Skip to content

Conversation

@MareStare
Copy link
Contributor

@MareStare MareStare commented May 21, 2025

This PR depends on this refactoring, so review+merge it first: #594

Example that this fixes is below. I reverted the first and the second change, which resulted only in tag1 being removed because tag2 and tag3 were already self-cancelled.

image

The new logic goes as this:

  1. Accept a map { tag_change_id => [tag_ids] | nil }.
  2. If the entry is nil - it means a request to revert changes to all tags in that TagChange, otherwise only revert the specified tag_ids within that TagChange.
  3. For this input, fetch the {image_id, tag_id, last_change: [change_id, added: boolean]} from the DB. Filter out any change where the first change and the last change to the tag are not equal (i.e. self-cancelling changes). The important nuance here is that we don't need to fetch intermediate tag changes! We only need to know the first and the last change in the sequence to effectively revert it.
  4. Fetch the IDs of the latest changes for each image/tag in the input.
  5. Keep only changes where the last_change is the actual last change that determined the current state of the tag on the image.
  6. Prepare the added/removed tag IDs for the image batch update logic

Also fixes this error when zero tag changes are selected:

@MareStare MareStare changed the title Fix reverts of self-canceling sequences, show effective tag changes on UI Fix reverts of self-canceling and non-current sequences, show effective tag changes on UI May 21, 2025
@MareStare MareStare force-pushed the feat/post-refactoring-and-fixing-tag-reverts branch from 78d2f08 to 1831604 Compare May 21, 2025 01:36
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.

2 participants