|
|
|
@ -8,6 +8,7 @@ import ( |
|
|
|
|
"html/template" |
|
|
|
|
"io" |
|
|
|
|
"net/http" |
|
|
|
|
"strconv" |
|
|
|
|
"sync" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
@ -175,17 +176,27 @@ func (d *diskvStorage) nextKey(post string) (string, error) { |
|
|
|
|
d.keyMtx.Lock() |
|
|
|
|
defer d.keyMtx.Unlock() |
|
|
|
|
|
|
|
|
|
var i uint64 |
|
|
|
|
|
|
|
|
|
prefix := post + "-" |
|
|
|
|
|
|
|
|
|
lastKey := prefix |
|
|
|
|
|
|
|
|
|
keys := d.KeysPrefix(prefix, nil) |
|
|
|
|
for range keys { |
|
|
|
|
i++ |
|
|
|
|
for key := range keys { |
|
|
|
|
lastKey = key |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if lastKey == prefix { |
|
|
|
|
return prefix + "1", nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
minusPrefix := lastKey[len(prefix):] |
|
|
|
|
lastIdx, err := strconv.Atoi(minusPrefix) |
|
|
|
|
if err != nil { |
|
|
|
|
return "", fmt.Errorf("comment key %q seems malformed", lastKey) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
key := prefix + fmt.Sprint(i) |
|
|
|
|
err := d.WriteStream(key, &bytes.Buffer{}, true) |
|
|
|
|
key := prefix + fmt.Sprint(lastIdx+1) |
|
|
|
|
err = d.WriteStream(key, &bytes.Buffer{}, true) |
|
|
|
|
|
|
|
|
|
return key, err |
|
|
|
|
} |
|
|
|
|