Skip to content

Commit 31e065a

Browse files
committed
fix(events): optimize GetEvent query for single record
Refactored GetEvent to use First instead of Find, improving performance and readability. This change ensures only one record is fetched by id, removes redundant error handling, and uses idiomatic GORM practices.
1 parent 6ee133a commit 31e065a

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

app/events/repository/get_event.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import (
99
func (repo *repository) GetEvent(ctx context.Context, eventID uint) (data domain.Event, err error) {
1010
db := repo.db.DB(ctx).Model(&domain.Event{})
1111

12-
err = db.Where("id = ?", eventID).Find(&data).Error
13-
if err != nil {
14-
return
15-
}
12+
err = db.Where("id = ?", eventID).First(&data).Error
1613

1714
return data, err
18-
}
15+
}

0 commit comments

Comments
 (0)