Use device datastore .Devices() method instead of GetDeviceByUDID.

Query by both device.SerialNumber and device.UDID
join WHERE conditions using the OR logical operator. I can't determine whether this has an impact elsewhere.
This commit is contained in:
Mosen
2016-06-25 22:19:39 +10:00
parent d69becfd53
commit 9a364d5c86
2 changed files with 13 additions and 3 deletions

View File

@@ -83,11 +83,21 @@ func (svc service) checkRequeue(deviceUDID string) (int, error) {
// Acknowledge Queries sent with DeviceInformation command
func (svc service) ackQueryResponses(req mdm.Response) error {
existing, err := svc.devices.GetDeviceByUDID(req.UDID, []string{"device_uuid", "serial_number"}...)
devices, err := svc.devices.Devices(
device.SerialNumber{SerialNumber: req.QueryResponses.SerialNumber},
device.UDID{UDID: req.UDID},
)
if err != nil {
return err
}
if len(devices) > 1 {
return errors.New("Expected a single query result for device, got more than one.")
}
existing := devices[0]
now := time.Now()
existing.LastCheckin = &now
existing.LastQueryResponse, err = json.Marshal(req.QueryResponses)
@@ -105,5 +115,5 @@ func (svc service) ackQueryResponses(req mdm.Response) error {
existing.OSVersion = req.QueryResponses.OSVersion
existing.SerialNumber = req.QueryResponses.SerialNumber
return svc.devices.Save("queryResponses", existing)
return svc.devices.Save("queryResponses", &existing)
}

View File

@@ -238,7 +238,7 @@ func addWhereFilters(stmt string, params ...interface{}) string {
}
if len(where) != 0 {
whereFilter := strings.Join(where, ",")
whereFilter := strings.Join(where, " OR ")
stmt = fmt.Sprintf("%s WHERE %s", stmt, whereFilter)
}
return stmt