Skip to content

Conversation

mlsmaycon
Copy link
Collaborator

@mlsmaycon mlsmaycon commented Jun 26, 2025

Describe your changes

This PR removes shared locking on read operations to avoid deadlocks and adds a GORM index on the UserID field in the Peer model.

  • Swapped all store.LockingStrengthShare usages for store.LockingStrengthNone on read calls.
  • Added a GORM index tag to Peer.UserID for improved lookup performance.

We've seen a few deadlock reports for queries with and without transactions that only needed to read data. This Pr removes the locking for share usage and left only the locking for update in use.

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

@Copilot Copilot AI review requested due to automatic review settings June 26, 2025 10:27
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes shared locking on read operations to avoid deadlocks and adds a GORM index on the UserID field in the Peer model.

  • Swapped all store.LockingStrengthShare usages for store.LockingStrengthNone on read calls.
  • Added a GORM index tag to Peer.UserID for improved lookup performance.

Reviewed Changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.

File Description
management/server/users/manager.go Switched read locks to no-lock for GetUserByUserID.
management/server/* Bulk replacement of shared locks with no-lock across various read methods.
management/server/peer/peer.go Added gorm:"index" tag to UserID field.

Status *PeerStatus `gorm:"embedded;embeddedPrefix:peer_status_"`
// The user ID that registered the peer
UserID string
UserID string `gorm:"index"`
Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

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

Adding a GORM index tag requires a corresponding database migration to ensure the index is created. Please add or update the migration script to add the user_id index on the peers table.

Copilot uses AI. Check for mistakes.

Copy link

@mlsmaycon mlsmaycon closed this Jun 27, 2025
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