(ctx context.Context, persistedCache dagql.PersistedObjectCache)
| 305 | } |
| 306 | |
| 307 | func (cache *CacheVolume) EncodePersistedObject(ctx context.Context, persistedCache dagql.PersistedObjectCache) (dagql.PersistedObjectEncoding, error) { |
| 308 | _ = ctx |
| 309 | if cache == nil { |
| 310 | return dagql.PersistedObjectEncoding{}, fmt.Errorf("encode persisted cache volume: nil cache volume") |
| 311 | } |
| 312 | var sourceResultID uint64 |
| 313 | if cache.Source.Valid { |
| 314 | encoded, err := encodePersistedObjectRef(persistedCache, cache.Source.Value, "cache volume source") |
| 315 | if err != nil { |
| 316 | return dagql.PersistedObjectEncoding{}, err |
| 317 | } |
| 318 | sourceResultID = encoded |
| 319 | } |
| 320 | cache.mu.Lock() |
| 321 | selector := cache.selector |
| 322 | if selector == "" { |
| 323 | selector = "/" |
| 324 | } |
| 325 | snapshotID := cache.snapshotID |
| 326 | var snapshotLinks []dagql.PersistedSnapshotRefLink |
| 327 | if cache.snapshot != nil { |
| 328 | snapshotID = cache.snapshot.SnapshotID() |
| 329 | } |
| 330 | if snapshotID != "" { |
| 331 | snapshotLinks = []dagql.PersistedSnapshotRefLink{{ |
| 332 | RefKey: snapshotID, |
| 333 | Role: "snapshot", |
| 334 | }} |
| 335 | } |
| 336 | cache.mu.Unlock() |
| 337 | payload, err := json.Marshal(persistedCacheVolumePayload{ |
| 338 | Key: cache.Key, |
| 339 | Namespace: cache.Namespace, |
| 340 | SourceResultID: sourceResultID, |
| 341 | Sharing: cache.Sharing, |
| 342 | Owner: cache.Owner, |
| 343 | Selector: selector, |
| 344 | }) |
| 345 | if err != nil { |
| 346 | return dagql.PersistedObjectEncoding{}, fmt.Errorf("marshal persisted cache volume payload: %w", err) |
| 347 | } |
| 348 | return dagql.PersistedObjectEncoding{ |
| 349 | JSON: payload, |
| 350 | SnapshotLinks: snapshotLinks, |
| 351 | }, nil |
| 352 | } |
| 353 | |
| 354 | func (cache *CacheVolume) lockKey() (string, error) { |
| 355 | if cache == nil { |
nothing calls this directly
no test coverage detected