Skip to content

Commit 56212f5

Browse files
committed
Use trans.Reader in WeakRead
This speeds things up considerably in case of no cache hit, as it avoids a full transaction in all cases. It may return a slightly stale value but never incur a lock.
1 parent 7e6648f commit 56212f5

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

collection.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,9 @@ func (c Collection) ReadWeak(
6565
maxStaleness time.Duration,
6666
) ([]byte, error) {
6767
p := paths.FromKey(c.prefix, key)
68-
lr, ok := c.local.Read(p, maxStaleness)
69-
if ok {
70-
return lr.Value, nil
71-
}
72-
// We don't have the value ready. We could read it from global storage,
73-
// but we would need to account for locked items. In case of lock create
74-
// we could read an empty object where instead it should be either not
75-
// found, or assume the first value.
76-
// Better to just use a readonly transaction.
77-
//
78-
// TODO: Use storage.Reader instead.
79-
return c.ReadStrong(ctx, key)
68+
r := trans.NewReader(c.local, c.global, c.db.tmon)
69+
rv, err := r.Read(ctx, p, maxStaleness)
70+
return rv.Value, err
8071
}
8172

8273
func (c Collection) Write(ctx context.Context, key, value []byte) error {

0 commit comments

Comments
 (0)