MCPcopy Create free account
hub / github.com/blues/note / hubNoteboxSummary

Function hubNoteboxSummary

lib/hubreq.go:1132–1190  ·  view source on GitHub ↗

Notebox Summary

(ctx context.Context, session *HubSession, req notehubMessage, rsp *notehubMessage, event EventFunc)

Source from the content-addressed store, hash-verified

1130
1131// Notebox Summary
1132func hubNoteboxSummary(ctx context.Context, session *HubSession, req notehubMessage, rsp *notehubMessage, event EventFunc) (err error) {
1133
1134 // Open the box
1135 box, ei, appUID, err2 := openHubNoteboxForDevice(ctx, session, req.DeviceUID, req.DeviceSN, req.ProductUID, req.DeviceEndpointID, event)
1136 if err2 != nil {
1137 err = err2
1138 return
1139 }
1140
1141 // Validate the session ID, and delete all local trackers to force resync if we've gotten out of sync
1142 // Note that this session ID will be flushed by our 5 minute checkpoint task and by normal session close.
1143 timerName := timerBegin(ctx, "swapTracker")
1144 sessionIDPrev := box.Notefile().swapTrackerSessionID(req.DeviceEndpointID, req.SessionIDNext)
1145 timerEnd(ctx, timerName)
1146 if sessionIDPrev != req.SessionIDPrev {
1147 if debugSync {
1148 logDebug(ctx, "Reset trackers because of ID mismatch (was %d, expecting %d now %d)", sessionIDPrev, req.SessionIDPrev, req.SessionIDNext)
1149 }
1150 box.ClearAllTrackers(ctx, req.DeviceEndpointID)
1151 rsp.SessionIDMismatch = true
1152 }
1153
1154 // Update the environment vars for the notebox, which may result in a changed _env.dbs
1155 timerName = timerBegin(ctx, "updateEnvVars")
1156 hubUpdateEnvVars(ctx, ei, box, req.DeviceUID, appUID, true)
1157 timerEnd(ctx, timerName)
1158
1159 // Get the info
1160 timerName = timerBegin(ctx, "getChangedNotefiles")
1161 fileChanges := box.GetChangedNotefiles(ctx, req.DeviceEndpointID)
1162 timerEnd(ctx, timerName)
1163
1164 // In an attempt to reduce the use of the buffer below, skim files that are obviously
1165 // never going to be "pulled" by the device, regardless of whether or not they were
1166 // technically modified on the service. The obvious things we're trying to skim off
1167 // are .qo, .qos, and anything ending in 'x' which is a local-only file
1168 f := fileChanges
1169 fileChanges = []string{}
1170 for _, file := range f {
1171 isQueue, syncToHub, syncFromHub, _, _, _ := NotefileAttributesFromID(file)
1172 if !(isQueue && syncToHub) && (syncToHub || syncFromHub) {
1173 fileChanges = append(fileChanges, file)
1174 }
1175 }
1176
1177 // Return the results truncated to fit within the protocol buffer (see notehub.options).
1178 // This is safe because it will simply take multiple passes to sync all of these files.
1179 rsp.NotefileIDs = fmt.Sprintf("%.*s", maxProtobufStringLength, strings.Join(fileChanges, ReservedIDDelimiter))
1180
1181 // Done
1182 box.Close(ctx)
1183
1184 // Every 12 hours, return the hub time to the device for its own clock calibration
1185 if notecardTimeNeedsCalibration(session) {
1186 rsp.HubTimeNs = time.Now().UnixNano()
1187 }
1188
1189 return err

Callers 1

processRequestFunction · 0.85

Calls 12

openHubNoteboxForDeviceFunction · 0.85
timerBeginFunction · 0.85
timerEndFunction · 0.85
logDebugFunction · 0.85
hubUpdateEnvVarsFunction · 0.85
NotefileAttributesFromIDFunction · 0.85
swapTrackerSessionIDMethod · 0.80
ClearAllTrackersMethod · 0.80
GetChangedNotefilesMethod · 0.80
NotefileMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected