d28f005552
Fix limit for databases other than sqlite go mod tidy && go mod vendor Remove unneeded break statements Make everything work with the new xorm version Fix xorm logging Fix lint Fix redis init Fix using id field Fix database init for testing Change default database log level Add xorm logger Use const for postgres go mod tidy Merge branch 'master' into update/xorm # Conflicts: # go.mod # go.sum # vendor/modules.txt go mod vendor Fix loading fixtures for postgres Go mod vendor1 Update xorm to version 1 Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/323
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package leveldb
|
|
|
|
import (
|
|
"github.com/syndtr/goleveldb/leveldb/storage"
|
|
"sync/atomic"
|
|
)
|
|
|
|
type iStorage struct {
|
|
storage.Storage
|
|
read uint64
|
|
write uint64
|
|
}
|
|
|
|
func (c *iStorage) Open(fd storage.FileDesc) (storage.Reader, error) {
|
|
r, err := c.Storage.Open(fd)
|
|
return &iStorageReader{r, c}, err
|
|
}
|
|
|
|
func (c *iStorage) Create(fd storage.FileDesc) (storage.Writer, error) {
|
|
w, err := c.Storage.Create(fd)
|
|
return &iStorageWriter{w, c}, err
|
|
}
|
|
|
|
func (c *iStorage) reads() uint64 {
|
|
return atomic.LoadUint64(&c.read)
|
|
}
|
|
|
|
func (c *iStorage) writes() uint64 {
|
|
return atomic.LoadUint64(&c.write)
|
|
}
|
|
|
|
// newIStorage returns the given storage wrapped by iStorage.
|
|
func newIStorage(s storage.Storage) *iStorage {
|
|
return &iStorage{s, 0, 0}
|
|
}
|
|
|
|
type iStorageReader struct {
|
|
storage.Reader
|
|
c *iStorage
|
|
}
|
|
|
|
func (r *iStorageReader) Read(p []byte) (n int, err error) {
|
|
n, err = r.Reader.Read(p)
|
|
atomic.AddUint64(&r.c.read, uint64(n))
|
|
return n, err
|
|
}
|
|
|
|
func (r *iStorageReader) ReadAt(p []byte, off int64) (n int, err error) {
|
|
n, err = r.Reader.ReadAt(p, off)
|
|
atomic.AddUint64(&r.c.read, uint64(n))
|
|
return n, err
|
|
}
|
|
|
|
type iStorageWriter struct {
|
|
storage.Writer
|
|
c *iStorage
|
|
}
|
|
|
|
func (w *iStorageWriter) Write(p []byte) (n int, err error) {
|
|
n, err = w.Writer.Write(p)
|
|
atomic.AddUint64(&w.c.write, uint64(n))
|
|
return n, err
|
|
}
|