|
@@ -67,6 +67,7 @@ func setApplication(target *models.Application, src *models.Application) {
|
|
|
|
|
|
func setDevice(target *models.Device, src *models.Device) {
|
|
|
target.ID = src.ID
|
|
|
+ target.RecordId = src.RecordId
|
|
|
target.ProductID = src.ProductID
|
|
|
target.DeviceIdentifier = src.DeviceIdentifier
|
|
|
target.DeviceSecret = src.DeviceSecret
|
|
@@ -379,20 +380,20 @@ func (r *Registry) FindDeviceById(args uint64, reply *models.Device) error {
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- //cache := getCache()
|
|
|
- //key := fmt.Sprintf("Device:%v", args)
|
|
|
- //if v, ok := cache.Get(key);ok {
|
|
|
- // device := v.(*models.Device)
|
|
|
- // setDevice(reply, device)
|
|
|
- //} else {
|
|
|
- d := &models.Device{}
|
|
|
- d.ID = uint(args)
|
|
|
- err = db.Where(d).First(reply).Error
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
+ cache := getCache()
|
|
|
+ key := fmt.Sprintf("Device:%v", args)
|
|
|
+ if v, ok := cache.Get(key); ok {
|
|
|
+ device := v.(*models.Device)
|
|
|
+ setDevice(reply, device)
|
|
|
+ } else {
|
|
|
+ d := &models.Device{}
|
|
|
+ d.ID = uint(args)
|
|
|
+ err = db.Where(d).First(reply).Error
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ cache.Set(key, reply)
|
|
|
}
|
|
|
- // cache.Set(key, reply)
|
|
|
- //}
|
|
|
|
|
|
return nil
|
|
|
}
|