MCPcopy Create free account
hub / github.com/encoder-run/operator / EncodedObjectSize

Method EncodedObjectSize

pkg/cache/redis/object.go:91–115  ·  view source on GitHub ↗

EncodedObjectSize implements storage.Storer.

(h plumbing.Hash)

Source from the content-addressed store, hash-verified

89
90// EncodedObjectSize implements storage.Storer.
91func (s *Storage) EncodedObjectSize(h plumbing.Hash) (int64, error) {
92 pattern := withNamespace(s.namespacePrefix, objectPrefix, fmt.Sprintf("*:%s", h.String()))
93 var cursor uint64
94 var err error
95 for {
96 // Scan for keys that match the hash pattern
97 var keys []string
98 keys, cursor, err = s.client.Scan(ctx, cursor, pattern, 1).Result()
99 if err != nil {
100 return 0, err
101 }
102 if len(keys) > 0 {
103 // Use STRLEN to get the size of the object stored at the found key
104 size, err := s.client.StrLen(ctx, keys[0]).Result()
105 if err != nil {
106 return 0, err
107 }
108 return size, nil
109 }
110 if cursor == 0 { // No more keys to scan
111 break
112 }
113 }
114 return 0, plumbing.ErrObjectNotFound
115}
116
117func (s *Storage) HasEncodedObject(h plumbing.Hash) error {
118 pattern := withNamespace(s.namespacePrefix, objectPrefix, fmt.Sprintf("*:%s", h.String()))

Callers

nothing calls this directly

Calls 2

withNamespaceFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected