mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-27 02:52:14 +01:00
fix(be): correct sorting for boltdb
This commit is contained in:
parent
482d24422b
commit
b60e927fc6
4
.gitignore
vendored
4
.gitignore
vendored
@ -6,7 +6,9 @@ web/public/html/**/*.*
|
||||
web/public/fonts/*.*
|
||||
web2/.nyc_output
|
||||
web2/dist/**/*
|
||||
config.json
|
||||
/config.json
|
||||
/.dredd/config.json
|
||||
/database.bolt
|
||||
.DS_Store
|
||||
node_modules/
|
||||
|
||||
|
@ -33,6 +33,7 @@ type ObjectProperties struct {
|
||||
ForeignColumnName string
|
||||
PrimaryColumnName string
|
||||
SortableColumns []string
|
||||
SortInverted bool
|
||||
}
|
||||
|
||||
var ErrNotFound = errors.New("no rows in result set")
|
||||
@ -206,6 +207,7 @@ var TaskProps = ObjectProperties{
|
||||
TableName: "task",
|
||||
IsGlobal: true,
|
||||
PrimaryColumnName: "id",
|
||||
SortInverted: true,
|
||||
}
|
||||
|
||||
var TaskOutputProps = ObjectProperties{
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
const MaxID = 2147483647
|
||||
|
||||
type enumerable interface {
|
||||
First() (key []byte, value []byte)
|
||||
@ -354,7 +355,7 @@ func (d *BoltDb) isObjectInUse(bucketID int, props db.ObjectProperties, objID ob
|
||||
reflect.Uint16,
|
||||
reflect.Uint32,
|
||||
reflect.Uint64:
|
||||
fVal = intObjectID(f.Int())
|
||||
fVal = intObjectID(2147483647 - f.Int())
|
||||
case reflect.String:
|
||||
fVal = strObjectID(f.String())
|
||||
}
|
||||
@ -529,8 +530,12 @@ func (d *BoltDb) createObject(bucketID int, props db.ObjectProperties, object in
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
if props.SortInverted {
|
||||
id = MaxID - id
|
||||
}
|
||||
idValue.SetInt(int64(id))
|
||||
}
|
||||
|
||||
objectID = intObjectID(idValue.Int())
|
||||
case reflect.String:
|
||||
if idValue.String() == "" {
|
||||
@ -551,6 +556,9 @@ func (d *BoltDb) createObject(bucketID int, props db.ObjectProperties, object in
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
if props.SortInverted {
|
||||
id = MaxID - id
|
||||
}
|
||||
objectID = intObjectID(id)
|
||||
}
|
||||
|
||||
|
@ -101,6 +101,8 @@ func (d *BoltDb) CreateEvent(evt db.Event) (newEvent db.Event, err error) {
|
||||
return err2
|
||||
}
|
||||
|
||||
id = MaxID - id
|
||||
|
||||
return b.Put(intObjectID(id).ToBytes(), str)
|
||||
})
|
||||
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"net/url"
|
||||
|
||||
@ -326,10 +327,13 @@ func (conf *ConfigType) GenerateCookieSecrets() {
|
||||
}
|
||||
|
||||
func (conf *ConfigType) ScanBoltDb() {
|
||||
fmt.Print(" > DB filename (default /tmp/boltdb): ")
|
||||
filename, err := os.Getwd() // os.UserHomeDir()
|
||||
exitOnConfigError(err)
|
||||
filename = filepath.Join(filename, "database.bolt")
|
||||
fmt.Print(" > DB filename (default " + filename + "): ")
|
||||
ScanErrorChecker(fmt.Scanln(&conf.BoltDb.Hostname))
|
||||
if len(conf.BoltDb.Hostname) == 0 {
|
||||
conf.BoltDb.Hostname = "/tmp/boltdb"
|
||||
conf.BoltDb.Hostname = filename
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user