Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Better postgres duplicate insert #2535

Merged
merged 4 commits into from
Mar 18, 2024

Conversation

Ivansete-status
Copy link
Collaborator

@Ivansete-status Ivansete-status commented Mar 15, 2024

Description

This PR implements a suggestion

After comparing insertion times with ~30.000 samples, within the archive module, these are the avg insert times:

  1. Without the change: 496 microseconds
  2. With the change: 453 microseconds

Then, this solution makes it even smoother the insertion. Thanks for such a suggestion @jakubgs !

Changes

  • add ON CONFLICT DO NOTHING; in the insert statement
  • adapt postgres test accordingly

How to test

  1. source env.sh
  2. nim c -r -d:chronicles_log_level=DEBUG -d:release -d:postgres -d:rln --passL:librln_v0.3.4.a --passL:-lm -d:nimDebugDlOpen ./tests/waku_archive/test_driver_postgres.nim

Issue

closes #2526
closes status-im/infra-status#26

@Ivansete-status Ivansete-status self-assigned this Mar 15, 2024
Copy link

This PR may contain changes to database schema of one of the drivers.

If you are introducing any changes to the schema, make sure the upgrade from the latest release to this change passes without any errors/issues.

Please make sure the label release-notes is added to make sure upgrade instructions properly highlight this change.

Copy link

github-actions bot commented Mar 15, 2024

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2535-rln-v2-true

Built from 54a6012

The insert does not fail when duplicate, it returns a positive response
when doing 'put' of a duplicated row. The test is adapted so that
we just check that the number of messages doesn't grow after
trying to add a duplicated row.
@Ivansete-status Ivansete-status force-pushed the better-postgres-duplicate-insert branch from e07e955 to 1ff0085 Compare March 15, 2024 23:22
@Ivansete-status Ivansete-status marked this pull request as ready for review March 18, 2024 08:26
Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter left a comment

Choose a reason for hiding this comment

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

Its great!!!! Thank you.

Copy link
Contributor

@jakubgs jakubgs left a comment

Choose a reason for hiding this comment

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

Does the DB no longer show warnings about duplicates?

@Ivansete-status
Copy link
Collaborator Author

Does the DB no longer show warnings about duplicates?

Correct

@Ivansete-status Ivansete-status merged commit 693a177 into master Mar 18, 2024
16 of 17 checks passed
@Ivansete-status Ivansete-status deleted the better-postgres-duplicate-insert branch March 18, 2024 14:59
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.

feat: prevent duplicate errors by using ON CONFLICT Duplicate key value errors for messages table
3 participants