From da84be235215187dcc5f7daca75917a238410599 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 12 Nov 2022 00:38:21 +0100 Subject: [PATCH] writeCacheReader: rename all vars to use full redable words --- server/gitea/cache.go | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/server/gitea/cache.go b/server/gitea/cache.go index b1d66f3..b11a370 100644 --- a/server/gitea/cache.go +++ b/server/gitea/cache.go @@ -71,32 +71,33 @@ type BranchTimestamp struct { } type writeCacheReader struct { - rc io.ReadCloser - buff *bytes.Buffer - f *FileResponse - cacheKey string - cache cache.SetGetKey - hasErr bool + originalReader io.ReadCloser + buffer *bytes.Buffer + rileResponse *FileResponse + cacheKey string + cache cache.SetGetKey + hasError bool } func (t *writeCacheReader) Read(p []byte) (n int, err error) { - n, err = t.rc.Read(p) + n, err = t.originalReader.Read(p) if err != nil { - t.hasErr = true + log.Trace().Err(err).Msgf("[cache] original reader for %q has returned an error", t.cacheKey) + t.hasError = true } else if n > 0 { - _, _ = t.buff.Write(p[:n]) + _, _ = t.buffer.Write(p[:n]) } return } func (t *writeCacheReader) Close() error { - if !t.hasErr { - fc := *t.f - fc.Body = t.buff.Bytes() + if !t.hasError { + fc := *t.rileResponse + fc.Body = t.buffer.Bytes() _ = t.cache.Set(t.cacheKey, fc, fileCacheTimeout) } - log.Trace().Msgf("cacheReader for %q saved=%t closed", t.cacheKey, !t.hasErr) - return t.rc.Close() + log.Trace().Msgf("cacheReader for %q saved=%t closed", t.cacheKey, !t.hasError) + return t.originalReader.Close() } func (f FileResponse) CreateCacheReader(r io.ReadCloser, cache cache.SetGetKey, cacheKey string) io.ReadCloser { @@ -106,10 +107,10 @@ func (f FileResponse) CreateCacheReader(r io.ReadCloser, cache cache.SetGetKey, } return &writeCacheReader{ - rc: r, - buff: bytes.NewBuffer(make([]byte, 0)), - f: &f, - cache: cache, - cacheKey: cacheKey, + originalReader: r, + buffer: bytes.NewBuffer(make([]byte, 0)), + rileResponse: &f, + cache: cache, + cacheKey: cacheKey, } }