mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-11-02 18:44:25 -05:00
Merge pull request #3682 from opencloud-eu/fix/search-stale-facet-metadata
perf(search): skip unchanged facet keys when storing metadata
This commit is contained in:
2 files changed
+23
-5
No files matched your search
@@ -735,8 +735,12 @@ func (s *Service) doUpsertItem(ctx context.Context, ref *provider.Reference, bat
|
||||
// the facet keys are ours, so the ones this extraction did not produce
|
||||
// describe content the resource no longer has
|
||||
var stale []string
|
||||
for k := range stat.GetInfo().GetArbitraryMetadata().GetMetadata() {
|
||||
if _, ok := metadata[k]; !ok && strings.HasPrefix(k, facetKeyPrefix) {
|
||||
for k, stored := range stat.GetInfo().GetArbitraryMetadata().GetMetadata() {
|
||||
value, ok := metadata[k]
|
||||
switch {
|
||||
case ok && value == stored:
|
||||
delete(metadata, k)
|
||||
case !ok && strings.HasPrefix(k, facetKeyPrefix):
|
||||
stale = append(stale, k)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,18 +248,32 @@ var _ = Describe("Searchprovider", func() {
|
||||
}, nil)
|
||||
|
||||
s.UpsertItem(&sprovider.Reference{ResourceId: info.GetId()})
|
||||
Expect(calls).To(Equal([]string{"set", "unset"}))
|
||||
Expect(calls).To(Equal([]string{"unset"}))
|
||||
Expect(unset).To(ConsistOf("libre.graph.retiredFacet.field"))
|
||||
})
|
||||
|
||||
It("removes nothing when the extraction still produces every stored facet", func() {
|
||||
It("writes only the keys whose value changed", func() {
|
||||
extractor.On("Extract", mock.Anything, mock.Anything, mock.Anything).Return(content.Document{
|
||||
Photo: &libregraph.Photo{CameraMake: libregraph.PtrString("Canon"), Iso: libregraph.PtrInt32(200)},
|
||||
Location: &libregraph.GeoCoordinates{Altitude: libregraph.PtrFloat64(12), Latitude: libregraph.PtrFloat64(48.1)},
|
||||
}, nil)
|
||||
|
||||
s.UpsertItem(&sprovider.Reference{ResourceId: info.GetId()})
|
||||
Expect(calls).To(Equal([]string{"set"}))
|
||||
Expect(set).To(Equal(map[string]string{
|
||||
"libre.graph.photo.iso": "200",
|
||||
"libre.graph.location.latitude": "48.1",
|
||||
}))
|
||||
})
|
||||
|
||||
It("does not touch the storage when the extraction still produces every stored facet unchanged", func() {
|
||||
extractor.On("Extract", mock.Anything, mock.Anything, mock.Anything).Return(content.Document{
|
||||
Photo: &libregraph.Photo{CameraMake: libregraph.PtrString("Canon"), Iso: libregraph.PtrInt32(100)},
|
||||
Location: &libregraph.GeoCoordinates{Altitude: libregraph.PtrFloat64(12)},
|
||||
}, nil)
|
||||
|
||||
s.UpsertItem(&sprovider.Reference{ResourceId: info.GetId()})
|
||||
Expect(calls).To(Equal([]string{"set"}))
|
||||
Expect(calls).To(BeEmpty())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user