Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(api): refactor device store #3270

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions api/store/mongo/device_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (s *Store) DeviceSetOnline(ctx context.Context, uid models.UID, timestamp t
}

collOptions := writeconcern.W1()
updateOptions := options.FindOneAndUpdate().SetUpsert(true).SetReturnDocument(options.Before)
updateOptions := options.FindOneAndUpdate().SetUpsert(false).SetReturnDocument(options.Before)

result := s.db.Collection("devices", options.Collection().SetWriteConcern(collOptions)).
FindOneAndUpdate(ctx, bson.M{"uid": uid},
Expand Down Expand Up @@ -401,8 +401,7 @@ func (s *Store) DeviceUpdateLastSeen(ctx context.Context, uid models.UID, ts tim
return nil
}

// DeviceUpdateStatus updates the status of a specific device in the devices collection and records the device's
// connection status in the connected_devices collection.
// DeviceUpdateStatus updates the status of a specific device in the devices collection
func (s *Store) DeviceUpdateStatus(ctx context.Context, uid models.UID, status models.DeviceStatus) error {
updateOptions := options.FindOneAndUpdate().SetReturnDocument(options.After)
result := s.db.Collection("devices", options.Collection()).
Expand All @@ -417,17 +416,6 @@ func (s *Store) DeviceUpdateStatus(ctx context.Context, uid models.UID, status m
return FromMongoError(err)
}

cd := &models.ConnectedDevice{
UID: device.UID,
TenantID: device.TenantID,
LastSeen: clock.Now(),
Status: string(status),
}

if _, err := s.db.Collection("connected_devices").InsertOne(ctx, &cd); err != nil {
return FromMongoError(err)
}

return nil
}

Expand Down
Loading