Retrieves the body etc. out of a revCacheValue. If they aren't already present, loads into the cache value using the provided document.
(ctx context.Context, backingStore RevisionCacheBackingStore, doc *Document)
| 756 | // Retrieves the body etc. out of a revCacheValue. If they aren't already present, loads into the cache value using |
| 757 | // the provided document. |
| 758 | func (value *revCacheValue) loadForDoc(ctx context.Context, backingStore RevisionCacheBackingStore, doc *Document) (docRev DocumentRevision, cacheHit bool, err error) { |
| 759 | |
| 760 | var revid string |
| 761 | value.lock.RLock() |
| 762 | if value.bodyBytes != nil || value.err != nil { |
| 763 | value.lock.RUnlock() |
| 764 | docRev, err = value.asDocumentRevision(nil) |
| 765 | |
| 766 | return docRev, true, err |
| 767 | } |
| 768 | value.lock.RUnlock() |
| 769 | |
| 770 | value.lock.Lock() |
| 771 | defer value.lock.Unlock() |
| 772 | // Check if the value was loaded while we waited for the lock - if so, return. |
| 773 | if value.bodyBytes != nil || value.err != nil { |
| 774 | cacheHit = true |
| 775 | } else { |
| 776 | // we only want to set can evict if we are having to load the doc from the bucket into value, |
| 777 | // avoiding setting this value multiple times in the case other goroutines are loading the same value |
| 778 | defer func() { |
| 779 | value.canEvict.Store(true) // once done loading doc we can set the value to be ready for eviction |
| 780 | }() |
| 781 | |
| 782 | cacheHit = false |
| 783 | hlv := &HybridLogicalVector{} |
| 784 | if value.revID == "" { |
| 785 | value.bodyBytes, value.history, value.channels, value.removed, value.attachments, value.deleted, value.expiry, revid, hlv, value.err = revCacheLoaderForDocumentCV(ctx, backingStore, doc, value.cv, false) |
| 786 | if revid != "" { |
| 787 | value.revID = revid |
| 788 | } |
| 789 | } else { |
| 790 | value.bodyBytes, value.history, value.channels, value.removed, value.attachments, value.deleted, value.expiry, hlv, value.err = revCacheLoaderForDocument(ctx, backingStore, doc, value.revID) |
| 791 | } |
| 792 | if hlv != nil { |
| 793 | value.cv = *hlv.ExtractCurrentVersionFromHLV() |
| 794 | value.hlvHistory = hlv.ToHistoryForHLV() |
| 795 | } |
| 796 | } |
| 797 | docRev, err = value.asDocumentRevision(nil) |
| 798 | // if not cache hit, we loaded from bucket. Calculate doc rev size and assign to rev cache value |
| 799 | if !cacheHit { |
| 800 | docRev.CalculateBytes() |
| 801 | value.itemBytes.Store(docRev.MemoryBytes) |
| 802 | } |
| 803 | return docRev, cacheHit, err |
| 804 | } |
| 805 | |
| 806 | // Stores a body etc. into a revCacheValue if there isn't one already. |
| 807 | func (value *revCacheValue) store(docRev DocumentRevision) { |
no test coverage detected