-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.go
75 lines (61 loc) · 1.45 KB
/
base.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package sdetools
import (
"fmt"
"log"
"path/filepath"
"github.com/boltdb/bolt"
)
type SDE struct {
BaseDir string
db *bolt.DB
loadedGroups bool
groups Groups
}
func (s *SDE) Init() {
db, err := bolt.Open(filepath.Join(s.BaseDir, "boltdb.bolt"), 0644, nil)
db.NoSync = true
if err != nil {
log.Fatal(err)
}
s.db = db
}
// Pre-build a BoltDB database of all the static data allowing
// fast local node access for all data without requiring it all
// in memory at all times, useful for running on very small
// compute instances
func (s *SDE) BuildBoltDB() {
s.db.Update(func(tx *bolt.Tx) error {
_, err := tx.CreateBucket([]byte(nameBucket))
if err != nil {
return fmt.Errorf("create bucket: %s", err)
}
return nil
})
s.loadNames()
s.db.Update(func(tx *bolt.Tx) error {
_, err := tx.CreateBucket([]byte(groupBucket))
if err != nil {
return fmt.Errorf("create bucket: %s", err)
}
return nil
})
s.loadGroups()
s.db.Update(func(tx *bolt.Tx) error {
_, _ = tx.CreateBucket([]byte(solarSystemNamesBucket))
_, _ = tx.CreateBucket([]byte(solarSystemIdsBucket))
return nil
})
s.loadUniverse()
s.db.Update(func(tx *bolt.Tx) error {
_, err := tx.CreateBucket([]byte(marketTypeBucket))
if err != nil {
return fmt.Errorf("create bucket: %s", err)
}
_, err = tx.CreateBucket([]byte(marketTypeNameBucket))
if err != nil {
return fmt.Errorf("create bucket: %s", err)
}
return nil
})
s.loadMarketTypes()
}