-
Notifications
You must be signed in to change notification settings - Fork 16
/
database.go
107 lines (89 loc) · 2.04 KB
/
database.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"database/sql"
"log"
c "github.com/Azareal/Gosora/common"
"github.com/pkg/errors"
)
var stmts *Stmts
var db *sql.DB
var dbAdapter string
// ErrNoRows is an alias of sql.ErrNoRows, just in case we end up with non-database/sql datastores
var ErrNoRows = sql.ErrNoRows
var _initDatabase func() error
func InitDatabase() (err error) {
stmts = &Stmts{Mocks: false}
// Engine specific code
err = _initDatabase()
if err != nil {
return err
}
globs = &Globs{stmts}
ws := errors.WithStack
log.Print("Running the db handlers.")
err = c.DbInits.Run()
if err != nil {
return ws(err)
}
log.Print("Loading the usergroups.")
c.Groups, err = c.NewMemoryGroupStore()
if err != nil {
return ws(err)
}
err2 := c.Groups.LoadGroups()
if err2 != nil {
return ws(err2)
}
// We have to put this here, otherwise LoadForums() won't be able to get the last poster data when building it's forums
log.Print("Initialising the user and topic stores")
var ucache c.UserCache
if c.Config.UserCache == "static" {
ucache = c.NewMemoryUserCache(c.Config.UserCacheCapacity)
}
var tcache c.TopicCache
if c.Config.TopicCache == "static" {
tcache = c.NewMemoryTopicCache(c.Config.TopicCacheCapacity)
}
c.Users, err = c.NewDefaultUserStore(ucache)
if err != nil {
return ws(err)
}
c.Topics, err = c.NewDefaultTopicStore(tcache)
if err != nil {
return ws(err)
}
log.Print("Loading the forums.")
c.Forums, err = c.NewMemoryForumStore()
if err != nil {
return ws(err)
}
err = c.Forums.LoadForums()
if err != nil {
return ws(err)
}
log.Print("Loading the forum permissions.")
c.FPStore, err = c.NewMemoryForumPermsStore()
if err != nil {
return ws(err)
}
err = c.FPStore.Init()
if err != nil {
return ws(err)
}
log.Print("Loading the settings.")
err = c.LoadSettings()
if err != nil {
return ws(err)
}
log.Print("Loading the plugins.")
err = c.InitExtend()
if err != nil {
return ws(err)
}
log.Print("Loading the themes.")
err = c.Themes.LoadActiveStatus()
if err != nil {
return ws(err)
}
return nil
}