From 028f2e3fb73b36def63e83f9d6c1e94b0c7097f5 Mon Sep 17 00:00:00 2001 From: Mauro Antonio Sanz Date: Wed, 27 Nov 2024 14:11:44 -0300 Subject: [PATCH] pr feedback --- splitio/proxy/caching/workers.go | 10 ++++++---- splitio/proxy/caching/workers_test.go | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/splitio/proxy/caching/workers.go b/splitio/proxy/caching/workers.go index b3d16827..52dc03ab 100644 --- a/splitio/proxy/caching/workers.go +++ b/splitio/proxy/caching/workers.go @@ -99,6 +99,7 @@ func (c *CacheAwareSegmentSynchronizer) SynchronizeSegment(name string, till *in result, err := c.wrapped.SynchronizeSegment(name, till) if current := result.NewChangeNumber; current > previous || (previous != -1 && current == -1) { c.cacheFlusher.EvictBySurrogate(MakeSurrogateForSegmentChanges(name)) + c.cacheFlusher.EvictBySurrogate(LargeSegmentSurrogate) } // remove individual entries for each affected key @@ -130,6 +131,7 @@ func (c *CacheAwareSegmentSynchronizer) SynchronizeSegments() (map[string]segmen if pcn, _ := previousCNs[segmentName]; ccn > pcn || (pcn > 0 && ccn == -1) { // if the segment was updated or the segment was removed, evict it c.cacheFlusher.EvictBySurrogate(MakeSurrogateForSegmentChanges(segmentName)) + c.cacheFlusher.EvictBySurrogate(LargeSegmentSurrogate) } for idx := range result.UpdatedKeys { @@ -182,7 +184,7 @@ func (c *CacheAwareLargeSegmentSynchronizer) SynchronizeLargeSegment(name string previous := c.largeSegmentStorage.ChangeNumber(name) newCN, err := c.wrapped.SynchronizeLargeSegment(name, till) - c.shouldEvictBySurrogate(previous, *newCN) + c.evictByLargeSegmentSurrogate(previous, *newCN) return newCN, err } @@ -199,7 +201,7 @@ func (c *CacheAwareLargeSegmentSynchronizer) SynchronizeLargeSegments() (map[str results, err := c.wrapped.SynchronizeLargeSegments() for name, currentCN := range results { - c.shouldEvictBySurrogate(previousCNs[name], *currentCN) + c.evictByLargeSegmentSurrogate(previousCNs[name], *currentCN) } return results, err @@ -213,12 +215,12 @@ func (c *CacheAwareLargeSegmentSynchronizer) SynchronizeLargeSegmentUpdate(lsRFD previous := c.largeSegmentStorage.ChangeNumber(lsRFDResponseDTO.Name) newCN, err := c.wrapped.SynchronizeLargeSegmentUpdate(lsRFDResponseDTO) - c.shouldEvictBySurrogate(previous, *newCN) + c.evictByLargeSegmentSurrogate(previous, *newCN) return newCN, err } -func (c *CacheAwareLargeSegmentSynchronizer) shouldEvictBySurrogate(previousCN int64, currentCN int64) { +func (c *CacheAwareLargeSegmentSynchronizer) evictByLargeSegmentSurrogate(previousCN int64, currentCN int64) { if currentCN > previousCN || currentCN == -1 { c.cacheFlusher.EvictBySurrogate(LargeSegmentSurrogate) } diff --git a/splitio/proxy/caching/workers_test.go b/splitio/proxy/caching/workers_test.go index 2c83d49a..4eaf70fe 100644 --- a/splitio/proxy/caching/workers_test.go +++ b/splitio/proxy/caching/workers_test.go @@ -144,6 +144,7 @@ func TestCacheAwareSegmentSyncSingle(t *testing.T) { cacheFlusher.On("EvictBySurrogate", MakeSurrogateForSegmentChanges("segment1")).Times(2) cacheFlusher.On("Evict", "/api/mySegments/k1").Times(2) cacheFlusher.On("Evict", "gzip::/api/mySegments/k1").Times(2) + cacheFlusher.On("EvictBySurrogate", LargeSegmentSurrogate).Times(2) var segmentStorage mocks.SegmentStorageMock segmentStorage.On("ChangeNumber", "segment1").Return(int64(0), nil).Once() @@ -189,6 +190,7 @@ func TestCacheAwareSegmentSyncAllSegments(t *testing.T) { cacheFlusher.On("EvictBySurrogate", MakeSurrogateForSegmentChanges("segment2")).Times(1) cacheFlusher.On("Evict", "/api/mySegments/k1").Times(3) cacheFlusher.On("Evict", "gzip::/api/mySegments/k1").Times(3) + cacheFlusher.On("EvictBySurrogate", LargeSegmentSurrogate).Times(3) var segmentStorage mocks.SegmentStorageMock segmentStorage.On("ChangeNumber", "segment2").Return(int64(0), nil).Once()