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

Method Upsert

db/revision_cache_lru.go:336–353  ·  view source on GitHub ↗

Upsert a revision in the cache.

(ctx context.Context, docRev DocumentRevision, collectionID uint32)

Source from the content-addressed store, hash-verified

334
335// Upsert a revision in the cache.
336func (rc *LRURevisionCache) Upsert(ctx context.Context, docRev DocumentRevision, collectionID uint32) {
337 // similar to PUT operation we should have the CV defined by this point (updateHLV is called before calling this)
338 key := IDandCV{DocID: docRev.DocID, Source: docRev.CV.SourceID, Version: docRev.CV.Value, CollectionID: collectionID}
339 legacyKey := IDAndRev{DocID: docRev.DocID, RevID: docRev.RevID, CollectionID: collectionID}
340
341 numItemsRemoved, value := rc.upsertDocToCache(ctx, key, legacyKey, docRev, collectionID)
342 if numItemsRemoved > 0 {
343 rc.cacheNumItems.Add(-numItemsRemoved)
344 }
345
346 docRev.CalculateBytes()
347 // add new item bytes to overall count
348 rc.incrRevCacheMemoryUsage(ctx, docRev.MemoryBytes)
349 value.store(docRev)
350
351 // check we aren't over memory capacity, if so perform eviction
352 rc.revCacheMemoryBasedEviction(ctx)
353}
354
355func (rc *LRURevisionCache) upsertDocToCache(ctx context.Context, cvKey IDandCV, legacyKey IDAndRev, docRev DocumentRevision, collectionID uint32) (int64, *revCacheValue) {
356 rc.lock.Lock()

Calls 6

upsertDocToCacheMethod · 0.95
CalculateBytesMethod · 0.80
storeMethod · 0.80
AddMethod · 0.45