mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-09-20 08:02:16 +02:00
perf, add index and transaction around create campaign
Signed-off-by: RonniSkansing <rskansing@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package database
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -20,3 +21,11 @@ type RecipientGroupRecipient struct {
|
||||
func (RecipientGroupRecipient) TableName() string {
|
||||
return RECIPIENT_GROUP_RECIPIENT_TABLE
|
||||
}
|
||||
|
||||
// Migrate adds an index leading with recipient_group_id. The existing unique index
|
||||
// leads with recipient_id, so counting or listing a group's members
|
||||
// (WHERE recipient_group_id = ?) could not use it and scanned the recipients per
|
||||
// group, making the group list quadratic in recipients times groups.
|
||||
func (RecipientGroupRecipient) Migrate(db *gorm.DB) error {
|
||||
return db.Exec(`CREATE INDEX IF NOT EXISTS idx_rgr_group ON recipient_group_recipients(recipient_group_id, recipient_id)`).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user