MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / revCacheLoaderForDocument

Function revCacheLoaderForDocument

db/revision_cache_interface.go:439–470  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

437// Common revCacheLoader functionality used either during a cache miss (from revCacheLoader), or directly when retrieving current rev from cache
438
439func 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

Callers 4

revCacheLoaderFunction · 0.85
GetWithRevMethod · 0.85
GetActiveMethod · 0.85
loadForDocMethod · 0.85

Calls 5

encodeRevisionsFunction · 0.85
IsChannelRemovalMethod · 0.80
getHistoryMethod · 0.80
getRevisionMethod · 0.65
GetRevTreeIDMethod · 0.45

Tested by

no test coverage detected