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

Fix PostgreSQL errors when a metric activity is recorded twice #393

Merged
merged 6 commits into from
Apr 16, 2020

Conversation

jaller94
Copy link
Contributor

Every time a user posts in a room they have already posted in on that day, the bridge outputs an error, if the metrics are enabled:

Apr-16 11:24:55.729 ERROR BridgedRoom Error storing activity metrics error: duplicate key value violates unique constraint "cons_activities_unique"
    at Connection.parseE (/home/jaller94/Git/Matrix/matrix-appservice-slack/node_modules/pg/lib/connection.js:614:13)
    at Connection.parseMessage (/home/jaller94/Git/Matrix/matrix-appservice-slack/node_modules/pg/lib/connection.js:413:19)
    at Socket.<anonymous> (/home/jaller94/Git/Matrix/matrix-appservice-slack/node_modules/pg/lib/connection.js:129:22)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:273:9)
    at Socket.Readable.push (_stream_readable.js:214:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
  name: 'error',
  length: 307,
  severity: 'ERROR',
  code: '23505',
  detail: 'Key (user_id, room_id, date)=(@jaller94:localhost, INTEG-Q9cv0tMFJgpsU7pC38KZ1xyR6zBlK07W, 2020-03-16) already exists.',
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: 'public',
  table: 'metrics_activities',
  column: undefined,
  dataType: undefined,
  constraint: 'cons_activities_unique',
  file: 'nbtinsert.c',
  line: '570',
  routine: '_bt_check_unique'
}

@jaller94 jaller94 changed the title Silence errors when an metric activity is recorded twice Silence PostgreSQL errors when a metric activity is recorded twice Apr 16, 2020
@jaller94 jaller94 requested a review from a team April 16, 2020 09:30
Copy link
Contributor

@Half-Shot Half-Shot left a comment

Choose a reason for hiding this comment

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

I'm not too happy about silencing errors if we can fix them

src/datastore/postgres/PgDatastore.ts Outdated Show resolved Hide resolved
@jaller94 jaller94 changed the title Silence PostgreSQL errors when a metric activity is recorded twice Fix PostgreSQL errors when a metric activity is recorded twice Apr 16, 2020
@Half-Shot
Copy link
Contributor

One more thing, would it be useful to have a test case for adding the same data twice into the datastore?

@jaller94 jaller94 assigned jaller94 and unassigned Half-Shot Apr 16, 2020
@jaller94
Copy link
Contributor Author

Now with 100% more tests that actually already caught a mistake.

@jaller94 jaller94 assigned Half-Shot and unassigned jaller94 Apr 16, 2020
@jaller94 jaller94 merged commit 95470fa into develop Apr 16, 2020
@jaller94 jaller94 deleted the j94/no-error-on-duplicate-activity branch April 16, 2020 17:08
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.

None yet

2 participants