Skip to content

Conversation

@jaskfla
Copy link
Contributor

@jaskfla jaskfla commented Oct 20, 2025

RN-1773

Causes headaches with duplicate options in option sets.

Stack 🥞

This is PR 2 of 2 in a stack:

  1. fix: RN-1773: conflict when MediTrak survey response creates 3+ identical options for an option set #6526
  2. This PR

Comment on lines 57 to 61
const uniqueOptionsCreated = new Map(
optionsCreated.map(option => [hashOption(option), option]),
).values();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

JavaScript Set uses reference equality here, and we can’t provide a custom hash function; so we achieve the same effect with a Map

Comment on lines +75 to +79
const sortOrder =
existingOption?.sort_order ??
((await models.option.getLargestSortOrder(optionSetId)) ?? 0) + 1;
Copy link
Contributor Author

@jaskfla jaskfla Oct 20, 2025

Choose a reason for hiding this comment

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

Nothing wrong with just using getLargestSortOrder every time; but this has the useless side effect of moving options from the middle of the sort order to the very end (and leaving a “gap”)

await db.runSql(`
BEGIN;

-- Delete duplicates to ensure (option_set_id, TRIM(value)) is unique
Copy link
Contributor Author

@jaskfla jaskfla Oct 20, 2025

Choose a reason for hiding this comment

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

Without this step, TRIM()-ing option.value will cause 16 conflicts (as of 20 October 2025)

Comment on lines +24 to +27
ROW_NUMBER() OVER (
PARTITION BY "option_set_id", TRIM("value")
ORDER BY "id"
) > 1 AS "is_duplicate"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Keeps the option with the “lowest” id (presumably the oldest entry); but this is arbitrary

@jaskfla jaskfla marked this pull request as ready for review October 20, 2025 04:40
@jaskfla
Copy link
Contributor Author

jaskfla commented Oct 20, 2025

bugbot run

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Base automatically changed from rn-1773-option to master October 23, 2025 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant