91f70d2a4a
Added basic support for server sync. Re-added a few missing defers. Renamed TO-DO to TODO across the entire codebase. Renamed StaticForumStore to MemoryForumStore. The ForumStore is now built on a sync.Map with a view slice for generating /forums rather than a slice. Renamed many more functions and variables to satisfy the linter. increase_post_user_stats() and decrease_post_user_stats() are now methods on the User struct. We also fix a bug where they take the moderator's score rather than the target user's into account when recalculating their level after a post / topic is deleted. Transitioned the topic list to CSS Grid for Tempra Simple, with a float fallback. Cosmo and Cosmo Conflux are now hidden from the theme list. Fixed more data races. Added more debug data to the template compiler logs.
70 lines
1.2 KiB
Go
70 lines
1.2 KiB
Go
package main
|
|
|
|
import "time"
|
|
|
|
var lastSync time.Time
|
|
|
|
func init() {
|
|
lastSync = time.Now()
|
|
}
|
|
|
|
func handleExpiredScheduledGroups() error {
|
|
rows, err := get_expired_scheduled_groups_stmt.Query()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
|
|
var uid int
|
|
for rows.Next() {
|
|
err := rows.Scan(&uid)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = replace_schedule_group_stmt.Exec(uid, 0, 0, time.Now(), false)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = set_temp_group_stmt.Exec(0, uid)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_ = users.Load(uid)
|
|
}
|
|
return rows.Err()
|
|
}
|
|
|
|
func handleServerSync() error {
|
|
var lastUpdate time.Time
|
|
var lastUpdateStr string
|
|
err := get_sync_stmt.QueryRow().Scan(&lastUpdateStr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
layout := "2006-01-02 15:04:05"
|
|
lastUpdate, err = time.Parse(layout, lastUpdateStr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if lastUpdate.After(lastSync) {
|
|
// TODO: A more granular sync
|
|
err = fstore.LoadForums()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// TODO: Resync the groups
|
|
// TODO: Resync the permissions
|
|
err = LoadSettings()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = LoadWordFilters()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|