Skip to content

Conversation

@faisal-chainlink
Copy link
Collaborator

What's in the PR?

  • Revert the original events query without deduping
  • Remove just-in-time events sync when calling QueryKey in the relayer
    • This will reduce the RPC load, make the responses quicker and remove the source of the events duplication
  • Add a new DB index to use an md5 hash over the event data along with the tx_digest and event_handle to ensure that duplicate events are not inserted.

IMPORTANT: Since we are adding a unique index, existing duplicates will require a clean up query to ensure that they are removed. The index creation will fail otherwise.

@faisal-chainlink faisal-chainlink requested a review from a team as a code owner January 5, 2026 13:56
@github-actions
Copy link

github-actions bot commented Jan 5, 2026

👋 faisal-chainlink, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@faisal-chainlink
Copy link
Collaborator Author

For removing the existing duplicates, we can use the following query:

WITH duplicates AS (
	SELECT id, ROW_NUMBER() OVER (
		PARTITION BY tx_digest, block_height, md5(data::text)
		ORDER BY event_offset DESC
	) as rn
	FROM sui.events
	WHERE event_account_address = $1 AND event_handle = $2
)
DELETE FROM sui.events
WHERE id IN (
	SELECT id FROM duplicates WHERE rn > 1
)

stackman27
stackman27 previously approved these changes Jan 5, 2026
stackman27
stackman27 previously approved these changes Jan 5, 2026
stackman27
stackman27 previously approved these changes Jan 5, 2026
@stackman27 stackman27 merged commit 26b1d50 into develop Jan 5, 2026
32 of 34 checks passed
@stackman27 stackman27 deleted the fix/duplicate-offsets branch January 5, 2026 18:24
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