MCPcopy
hub / github.com/dosco/graphjin / ProcessForCache

Method ProcessForCache

core/cache_response.go:235–275  ·  view source on GitHub ↗

ProcessForCache extracts row references and strips __gj_id from response. Returns the cleaned response and list of (table, row_id) pairs.

(data []byte)

Source from the content-addressed store, hash-verified

233// ProcessForCache extracts row references and strips __gj_id from response.
234// Returns the cleaned response and list of (table, row_id) pairs.
235func (rp *ResponseProcessor) ProcessForCache(data []byte) (cleaned []byte, refs []RowRef, err error) {
236 if len(data) == 0 {
237 return data, nil, nil
238 }
239 if rp.qc == nil {
240 return data, nil, nil
241 }
242
243 // Parse JSON response
244 var result map[string]interface{}
245 if err = json.Unmarshal(data, &result); err != nil {
246 return data, nil, err
247 }
248
249 dataMap, ok := responseDataMap(result)
250 if !ok {
251 return data, nil, nil
252 }
253
254 refs = make([]RowRef, 0, 100)
255
256 // Process each root selection
257 for i := range rp.qc.Selects {
258 sel := &rp.qc.Selects[i]
259 if sel.ParentID != -1 {
260 continue // Skip non-root selections
261 }
262
263 fieldName := sel.FieldName
264 if fieldName == "" {
265 fieldName = sel.Table
266 }
267
268 if fieldData, ok := dataMap[fieldName]; ok {
269 rp.processNode(sel.Table, fieldData, &refs, sel)
270 }
271 }
272
273 cleaned, err = stripCacheTrackingFields(data)
274 return
275}
276
277func stripCacheTrackingFields(data []byte) ([]byte, error) {
278 fields := jsn.Get(data, [][]byte{[]byte("__gj_id")})

Calls 3

processNodeMethod · 0.95
responseDataMapFunction · 0.85
stripCacheTrackingFieldsFunction · 0.85