unified-storage: Skip query when ListModifiedSince cannot return anything. (#110338)

* Skip query when ListModifiedSince cannot return anything.

* Only save listRV if it's different than sinceRV. This saves a disk access if not needed.

* Add test for ListModifiedSince with same RV.
This commit is contained in:
Peter Štibraný
2025-08-29 14:49:20 +02:00
committed by GitHub
parent e3f5a65372
commit 3a3ba483b1
3 changed files with 44 additions and 10 deletions
+24 -4
View File
@@ -3,6 +3,7 @@ package test
import (
"context"
"fmt"
"iter"
"net/http"
"slices"
"strings"
@@ -523,11 +524,22 @@ func runTestIntegrationBackendListModifiedSince(t *testing.T, backend resource.S
latestRv, seq := backend.ListModifiedSince(ctx, key, rvDeleted)
require.GreaterOrEqual(t, latestRv, rvDeleted)
counter := 0
for range seq {
counter++
isEmpty(t, seq)
})
t.Run("no events for subsequent listModifiedSince calls", func(t *testing.T) {
key := resource.NamespacedResource{
Namespace: ns,
Group: "group",
Resource: "resource",
}
require.Equal(t, 0, counter) // no events should be returned
latestRv1, seq := backend.ListModifiedSince(ctx, key, rvDeleted)
require.GreaterOrEqual(t, latestRv1, rvDeleted)
isEmpty(t, seq)
latestRv2, seq := backend.ListModifiedSince(ctx, key, latestRv1)
require.GreaterOrEqual(t, latestRv1, latestRv2)
isEmpty(t, seq)
})
t.Run("will only return modified events for the given key", func(t *testing.T) {
@@ -582,6 +594,14 @@ func runTestIntegrationBackendListModifiedSince(t *testing.T, backend resource.S
})
}
func isEmpty(t *testing.T, seq iter.Seq2[*resource.ModifiedResource, error]) {
counter := 0
for range seq {
counter++
}
require.Equal(t, 0, counter)
}
func runTestIntegrationBackendListHistory(t *testing.T, backend resource.StorageBackend, nsPrefix string) {
ctx := testutil.NewTestContext(t, time.Now().Add(30*time.Second))
server := newServer(t, backend)