Common revCacheLoader functionality used either during a cache miss (from revCacheLoader), or directly when retrieving current rev from cache
(ctx context.Context, backingStore RevisionCacheBackingStore, doc *Document, revid string)
| 437 | // Common revCacheLoader functionality used either during a cache miss (from revCacheLoader), or directly when retrieving current rev from cache |
| 438 | |
| 439 | func revCacheLoaderForDocument(ctx context.Context, backingStore RevisionCacheBackingStore, doc *Document, revid string) (bodyBytes []byte, history Revisions, channels base.Set, removed bool, attachments AttachmentsMeta, deleted bool, expiry *time.Time, hlv *HybridLogicalVector, err error) { |
| 440 | if bodyBytes, attachments, channels, err = backingStore.getRevision(ctx, doc, revid); err != nil { |
| 441 | // If we can't find the revision (either as active or conflicted body from the document, or as old revision body backup), check whether |
| 442 | // the revision was a channel removal. If so, we want to store as removal in the revision cache |
| 443 | removalBodyBytes, removalHistory, activeChannels, isRemoval, isDelete, isRemovalErr := doc.IsChannelRemoval(ctx, revid) |
| 444 | if isRemovalErr != nil { |
| 445 | return bodyBytes, history, channels, isRemoval, nil, isDelete, nil, hlv, isRemovalErr |
| 446 | } |
| 447 | |
| 448 | if isRemoval { |
| 449 | return removalBodyBytes, removalHistory, activeChannels, isRemoval, nil, isDelete, nil, hlv, nil |
| 450 | } |
| 451 | |
| 452 | // If this wasn't a removal, return the original error from getRevision |
| 453 | return bodyBytes, history, channels, removed, nil, isDelete, nil, hlv, err |
| 454 | } |
| 455 | deleted = doc.History[revid].Deleted |
| 456 | |
| 457 | validatedHistory, getHistoryErr := doc.History.getHistory(revid) |
| 458 | if getHistoryErr != nil { |
| 459 | return bodyBytes, history, channels, removed, nil, deleted, nil, hlv, getHistoryErr |
| 460 | } |
| 461 | history = encodeRevisions(ctx, doc.ID, validatedHistory) |
| 462 | // only add doc hlv if the revision we have fetched is current revision, otherwise we don't know whether hlv applies to that revision |
| 463 | if doc.GetRevTreeID() == revid { |
| 464 | if doc.HLV != nil { |
| 465 | hlv = doc.HLV |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | return bodyBytes, history, channels, removed, attachments, deleted, doc.Expiry, hlv, err |
| 470 | } |
| 471 | |
| 472 | // revCacheLoaderForDocumentCV used either during cache miss (from revCacheLoaderForCv), or used directly when getting current active CV from cache |
| 473 | // nolint:staticcheck |
no test coverage detected