a5f5f4af7e
Added the PageStore. Renamed account_own_edit.html to account_own_edit_password.html Renamed custom-page.html to custom_page.html Renamed the pre_render_custom_page hook to pre_render_tmpl_page. Added a new pre_render_custom_page hook, not to be confused with the previous one. Renamed the pre_render_account_own_edit_critical hook to pre_render_account_own_edit_password. Moved the report forum ID into a constant. Renamed todaysReportCount to topicsTopicCountByForum and made it more generic. Renamed panel-menu.html to panel_menu.html Renamed panel-inner-menu.html to panel_inner_menu.html Removed an irrelevant editable_parent in a no results row. Fixed the profile page loading the wrong profile.css Fixed a bug where the last poster avatar would break on the forum page. Added the AddNotice method to *Header. Greatly simplified many of the page struct definitions. Added the ErrorPage page struct and refactored the error pages to use it. Added the BasePanelPage page struct and refactored the panel page structs to use it. Tweaked the DefaultHeader function to set the user on the spot rather than after the fact. Simplified AccountEditAvatarSubmit into a redirect. Add the addElement closure in the control panel dashboard to reduce the amount of complexity. Tweaked LogWarning to better handle nils. Added the account_username phrase. Added the account_avatar phrase. Added the account_email phrase. Added the panel_pages phrase. Added the panel_pages_edit phrase. Added the panel_page_created phrase. Added the panel_page_updated phrase. Added the panel_page_deleted phrase. Added the account_menu_security phrase. Added the panel_menu_pages phrase. Added the panel_pages_head phrase. Added the panel_pages_edit_button_aria phrase. Added the panel_pages_delete_button_aria phrase. Added the panel_pages_no_pages phrase. Added the panel_pages_create_head phrase. Added the panel_pages_create_name phrase. Added the panel_pages_create_name_placeholder phrase. Added the panel_pages_create_title phrase. Added the panel_pages_create_title_placeholder phrase. Added the panel_pages_create_body_placeholder phrase. Added the panel_pages_create_submit_button phrase. Added the panel_pages_edit_head phrase. Added the panel_pages_name phrase. Added the panel_pages_title phrase. Added the panel_pages_edit_update_button phrase. Began work on two-factor authentication. Made more progress with the Nox Theme.
93 lines
3.2 KiB
Go
93 lines
3.2 KiB
Go
// +build !pgsql, !sqlite, !mssql
|
|
|
|
/*
|
|
*
|
|
* Gosora MySQL Interface
|
|
* Copyright Azareal 2016 - 2019
|
|
*
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"./common"
|
|
"./query_gen/lib"
|
|
_ "github.com/go-sql-driver/mysql"
|
|
)
|
|
|
|
var dbCollation = "utf8mb4_general_ci"
|
|
|
|
func init() {
|
|
dbAdapter = "mysql"
|
|
_initDatabase = initMySQL
|
|
}
|
|
|
|
func initMySQL() (err error) {
|
|
err = qgen.Builder.Init("mysql", map[string]string{
|
|
"host": common.DbConfig.Host,
|
|
"port": common.DbConfig.Port,
|
|
"name": common.DbConfig.Dbname,
|
|
"username": common.DbConfig.Username,
|
|
"password": common.DbConfig.Password,
|
|
"collation": dbCollation,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Set the number of max open connections
|
|
db = qgen.Builder.GetConn()
|
|
db.SetMaxOpenConns(64)
|
|
db.SetMaxIdleConns(32)
|
|
|
|
// Only hold connections open for five seconds to avoid accumulating a large number of stale connections
|
|
//db.SetConnMaxLifetime(5 * time.Second)
|
|
|
|
// Build the generated prepared statements, we are going to slowly move the queries over to the query generator rather than writing them all by hand, this'll make it easier for us to implement database adapters for other databases like PostgreSQL, MSSQL, SQlite, etc.
|
|
err = _gen_mysql()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// TODO: Is there a less noisy way of doing this for tests?
|
|
log.Print("Preparing getActivityFeedByWatcher statement.")
|
|
stmts.getActivityFeedByWatcher, err = db.Prepare("SELECT activity_stream_matches.asid, activity_stream.actor, activity_stream.targetUser, activity_stream.event, activity_stream.elementType, activity_stream.elementID FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ? ORDER BY activity_stream.asid DESC LIMIT 8")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Print("Preparing getActivityCountByWatcher statement.")
|
|
stmts.getActivityCountByWatcher, err = db.Prepare("SELECT count(*) FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ?")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Print("Preparing todaysPostCount statement.")
|
|
stmts.todaysPostCount, err = db.Prepare("select count(*) from replies where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp()")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Print("Preparing todaysTopicCount statement.")
|
|
stmts.todaysTopicCount, err = db.Prepare("select count(*) from topics where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp()")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Print("Preparing todaysTopicCountByForum statement.")
|
|
// TODO: Stop hard-coding this query
|
|
stmts.todaysTopicCountByForum, err = db.Prepare("select count(*) from topics where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp() and parentID = ?")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Print("Preparing todaysNewUserCount statement.")
|
|
stmts.todaysNewUserCount, err = db.Prepare("select count(*) from users where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp()")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|