gosora/database.go
Azareal b9973719a5 Added a small reply cache.
Preloaded a small number of users and topics.
Use cache.Set instead of cache.Add in a few spots for topics to avoid issues with the counter falling out of sync with the cache length.
Embed Reply in ReplyUser instead of duplicating the same fields.
Add the missing AttachCount and ActionType fields to Reply.
Add the missing Poll field to TopicsRow.
Added the TopicUser.Replies method to better abstract the reply list generation logic.
Shortened some common.s to c.s
Moved memStuff out of the analytics memory panes and into analytics.js
Removed the temporary preStats fix for label overflow now that we have a better solution.
Added the panel_analytics_script_memory template to help de-dupe logic in the analytics memory panes.
Added the Topic method to TopicsRow.
Added the GetRidsForTopic method to help cache replies in a small set of scenarios.

Added the ReplyCache config.json setting.
Added the ReplyCacheCapacity config.json setting.

Added a parser test case.
Added more Reply and ReplyStore related test cases.
2019-05-17 18:40:41 +10:00

107 lines
2.2 KiB
Go

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}
log.Print("Running the db handlers.")
err = c.DbInits.Run()
if err != nil {
return errors.WithStack(err)
}
log.Print("Loading the usergroups.")
c.Groups, err = c.NewMemoryGroupStore()
if err != nil {
return errors.WithStack(err)
}
err2 := c.Groups.LoadGroups()
if err2 != nil {
return errors.WithStack(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 errors.WithStack(err)
}
c.Topics, err = c.NewDefaultTopicStore(tcache)
if err != nil {
return errors.WithStack(err2)
}
log.Print("Loading the forums.")
c.Forums, err = c.NewMemoryForumStore()
if err != nil {
return errors.WithStack(err)
}
err = c.Forums.LoadForums()
if err != nil {
return errors.WithStack(err)
}
log.Print("Loading the forum permissions.")
c.FPStore, err = c.NewMemoryForumPermsStore()
if err != nil {
return errors.WithStack(err)
}
err = c.FPStore.Init()
if err != nil {
return errors.WithStack(err)
}
log.Print("Loading the settings.")
err = c.LoadSettings()
if err != nil {
return errors.WithStack(err)
}
log.Print("Loading the plugins.")
err = c.InitExtend()
if err != nil {
return errors.WithStack(err)
}
log.Print("Loading the themes.")
err = c.Themes.LoadActiveStatus()
if err != nil {
return errors.WithStack(err)
}
return nil
}