[go: nahoru, domu]

Skip to content

Commit

Permalink
api: set session as "closed" to avoid reinsertion in active_sessions
Browse files Browse the repository at this point in the history
Co-authored-by: vsaller <vsaller@yahoo.com>
Co-authored-by: Luis Gustavo S. Barreto <gustavo@ossystems.com.br>
  • Loading branch information
3 people committed Jul 30, 2021
1 parent cff11a0 commit 6ead3a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/store/mongo/session_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ func (s *Store) SessionSetLastSeen(ctx context.Context, uid models.UID) error {
return fromMongoError(err)
}

if session.Closed {
return nil
}

session.LastSeen = clock.Now()

opts := options.Update().SetUpsert(true)
Expand Down Expand Up @@ -205,6 +209,8 @@ func (s *Store) SessionDeleteActives(ctx context.Context, uid models.UID) error
}

session.LastSeen = clock.Now()
session.Closed = true

opts := options.Update().SetUpsert(true)
_, err := s.db.Collection("sessions").UpdateOne(ctx, bson.M{"uid": session.UID}, bson.M{"$set": session}, opts)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/models/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Session struct {
StartedAt time.Time `json:"started_at" bson:"started_at"`
LastSeen time.Time `json:"last_seen" bson:"last_seen"`
Active bool `json:"active" bson:",omitempty"`
Closed bool `json:"-" bson:"closed"`
Authenticated bool `json:"authenticated" bson:"authenticated"`
Recorded bool `json:"recorded" bson:"recorded"`
}
Expand Down

0 comments on commit 6ead3a7

Please sign in to comment.