mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-21 19:39:43 +01:00
upgrade buntdb
This commit is contained in:
parent
ce41f501c9
commit
82c50cc497
2
go.mod
2
go.mod
@ -17,7 +17,7 @@ require (
|
||||
github.com/onsi/ginkgo v1.12.0 // indirect
|
||||
github.com/onsi/gomega v1.9.0 // indirect
|
||||
github.com/stretchr/testify v1.4.0 // indirect
|
||||
github.com/tidwall/buntdb v1.2.10
|
||||
github.com/tidwall/buntdb v1.3.1
|
||||
github.com/toorop/go-dkim v0.0.0-20201103131630-e1cd1a0a5208
|
||||
github.com/xdg-go/scram v1.0.2
|
||||
golang.org/x/crypto v0.17.0
|
||||
|
2
go.sum
2
go.sum
@ -49,6 +49,8 @@ github.com/tidwall/btree v1.4.2 h1:PpkaieETJMUxYNADsjgtNRcERX7mGc/GP2zp/r5FM3g=
|
||||
github.com/tidwall/btree v1.4.2/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE=
|
||||
github.com/tidwall/buntdb v1.2.10 h1:U/ebfkmYPBnyiNZIirUiWFcxA/mgzjbKlyPynFsPtyM=
|
||||
github.com/tidwall/buntdb v1.2.10/go.mod h1:lZZrZUWzlyDJKlLQ6DKAy53LnG7m5kHyrEHvvcDmBpU=
|
||||
github.com/tidwall/buntdb v1.3.1 h1:HKoDF01/aBhl9RjYtbaLnvX9/OuenwvQiC3OP1CcL4o=
|
||||
github.com/tidwall/buntdb v1.3.1/go.mod h1:lZZrZUWzlyDJKlLQ6DKAy53LnG7m5kHyrEHvvcDmBpU=
|
||||
github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw=
|
||||
github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
|
38
vendor/github.com/tidwall/buntdb/buntdb.go
generated
vendored
38
vendor/github.com/tidwall/buntdb/buntdb.go
generated
vendored
@ -61,6 +61,8 @@ var (
|
||||
ErrTxIterating = errors.New("tx is iterating")
|
||||
)
|
||||
|
||||
const useAbsEx = true
|
||||
|
||||
// DB represents a collection of key-value pairs that persist on disk.
|
||||
// Transactions are used for all forms of data access to the DB.
|
||||
type DB struct {
|
||||
@ -895,24 +897,35 @@ func (db *DB) readLoad(rd io.Reader, modTime time.Time) (n int64, err error) {
|
||||
return totalSize, ErrInvalid
|
||||
}
|
||||
if len(parts) == 5 {
|
||||
if strings.ToLower(parts[3]) != "ex" {
|
||||
arg := strings.ToLower(parts[3])
|
||||
if arg != "ex" && arg != "ae" {
|
||||
return totalSize, ErrInvalid
|
||||
}
|
||||
ex, err := strconv.ParseUint(parts[4], 10, 64)
|
||||
ex, err := strconv.ParseInt(parts[4], 10, 64)
|
||||
if err != nil {
|
||||
return totalSize, err
|
||||
}
|
||||
var exat time.Time
|
||||
now := time.Now()
|
||||
dur := (time.Duration(ex) * time.Second) - now.Sub(modTime)
|
||||
if dur > 0 {
|
||||
if arg == "ex" {
|
||||
dur := (time.Duration(ex) * time.Second) - now.Sub(modTime)
|
||||
exat = now.Add(dur)
|
||||
} else {
|
||||
exat = time.Unix(ex, 0)
|
||||
}
|
||||
if exat.After(now) {
|
||||
db.insertIntoDatabase(&dbItem{
|
||||
key: parts[1],
|
||||
val: parts[2],
|
||||
opts: &dbItemOpts{
|
||||
ex: true,
|
||||
exat: now.Add(dur),
|
||||
exat: exat,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
db.deleteFromDatabase(&dbItem{
|
||||
key: parts[1],
|
||||
})
|
||||
}
|
||||
} else {
|
||||
db.insertIntoDatabase(&dbItem{key: parts[1], val: parts[2]})
|
||||
@ -1330,13 +1343,19 @@ func appendBulkString(buf []byte, s string) []byte {
|
||||
// writeSetTo writes an item as a single SET record to the a bufio Writer.
|
||||
func (dbi *dbItem) writeSetTo(buf []byte, now time.Time) []byte {
|
||||
if dbi.opts != nil && dbi.opts.ex {
|
||||
ex := dbi.opts.exat.Sub(now) / time.Second
|
||||
buf = appendArray(buf, 5)
|
||||
buf = appendBulkString(buf, "set")
|
||||
buf = appendBulkString(buf, dbi.key)
|
||||
buf = appendBulkString(buf, dbi.val)
|
||||
buf = appendBulkString(buf, "ex")
|
||||
buf = appendBulkString(buf, strconv.FormatUint(uint64(ex), 10))
|
||||
if useAbsEx {
|
||||
ex := dbi.opts.exat.Unix()
|
||||
buf = appendBulkString(buf, "ae")
|
||||
buf = appendBulkString(buf, strconv.FormatUint(uint64(ex), 10))
|
||||
} else {
|
||||
ex := dbi.opts.exat.Sub(now) / time.Second
|
||||
buf = appendBulkString(buf, "ex")
|
||||
buf = appendBulkString(buf, strconv.FormatUint(uint64(ex), 10))
|
||||
}
|
||||
} else {
|
||||
buf = appendArray(buf, 3)
|
||||
buf = appendBulkString(buf, "set")
|
||||
@ -1622,6 +1641,9 @@ func (tx *Tx) scan(desc, gt, lt bool, index, start, stop string,
|
||||
// wrap a btree specific iterator around the user-defined iterator.
|
||||
iter := func(item interface{}) bool {
|
||||
dbi := item.(*dbItem)
|
||||
if dbi.expired() {
|
||||
return true
|
||||
}
|
||||
return iterator(dbi.key, dbi.val)
|
||||
}
|
||||
var tr *btree.BTree
|
||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -48,7 +48,7 @@ github.com/okzk/sdnotify
|
||||
# github.com/tidwall/btree v1.4.2
|
||||
## explicit; go 1.18
|
||||
github.com/tidwall/btree
|
||||
# github.com/tidwall/buntdb v1.2.10
|
||||
# github.com/tidwall/buntdb v1.3.1
|
||||
## explicit; go 1.18
|
||||
github.com/tidwall/buntdb
|
||||
# github.com/tidwall/gjson v1.14.3
|
||||
|
Loading…
Reference in New Issue
Block a user