Skip to content

Commit

Permalink
fix/BCF-2497: refactoring out redundant query implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhuie19 committed Sep 5, 2023
1 parent 505f367 commit 00d005d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/sessions/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ func (o *orm) AuthorizedUserWithSession(sessionID string) (User, error) {
return User{}, ErrUserSessionExpired
}

if err := o.q.Get(&user, "SELECT * FROM users WHERE lower(email) = lower($1)", foundSession.Email); err != nil {
user, err := o.findUser(foundSession.Email)
if err != nil {
return User{}, errors.Wrap(err, "no matching user for provided session email")
}

err := o.q.Transaction(func(tx pg.Queryer) error {
err = o.q.Transaction(func(tx pg.Queryer) error {
// Session valid and tied to user, update last_used
_, err := tx.Exec("UPDATE sessions SET last_used = now() WHERE id = $1 AND last_used + $2 >= now()", sessionID, o.sessionDuration)
if err != nil {
Expand Down

0 comments on commit 00d005d

Please sign in to comment.