2018-07-29 04:17:17 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-01-02 05:28:36 +00:00
|
|
|
"database/sql"
|
2018-07-29 04:17:17 +00:00
|
|
|
"log"
|
2019-05-09 06:58:55 +00:00
|
|
|
"strconv"
|
2020-01-02 05:28:36 +00:00
|
|
|
"time"
|
2018-07-29 04:17:17 +00:00
|
|
|
|
2019-04-19 08:20:10 +00:00
|
|
|
c "github.com/Azareal/Gosora/common"
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
"github.com/pkg/errors"
|
2018-07-29 04:17:17 +00:00
|
|
|
)
|
|
|
|
|
2021-05-02 08:47:19 +00:00
|
|
|
var TickLoop *c.TickLoop
|
2018-07-29 04:17:17 +00:00
|
|
|
|
2021-05-02 08:47:19 +00:00
|
|
|
func runHook(name string) error {
|
2021-03-23 10:21:56 +00:00
|
|
|
if e := c.RunTaskHook(name); e != nil {
|
2021-05-02 08:47:19 +00:00
|
|
|
return errors.Wrap(e, "Failed at task '"+name+"'")
|
2018-07-29 04:17:17 +00:00
|
|
|
}
|
2021-05-02 08:47:19 +00:00
|
|
|
return nil
|
2018-07-29 04:17:17 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 08:47:19 +00:00
|
|
|
func deferredDailies() error {
|
|
|
|
lastDailyStr, e := c.Meta.Get("lastDaily")
|
2019-05-09 06:58:55 +00:00
|
|
|
// TODO: Report this error back correctly...
|
2021-05-02 08:47:19 +00:00
|
|
|
if e != nil && e != sql.ErrNoRows {
|
|
|
|
return e
|
2019-05-09 06:58:55 +00:00
|
|
|
}
|
|
|
|
lastDaily, _ := strconv.ParseInt(lastDailyStr, 10, 64)
|
2019-07-26 22:36:06 +00:00
|
|
|
low := time.Now().Unix() - (60 * 60 * 24)
|
2019-05-09 06:58:55 +00:00
|
|
|
if lastDaily < low {
|
2021-05-02 08:47:19 +00:00
|
|
|
if e := c.Dailies(); e != nil {
|
|
|
|
return e
|
2021-03-23 10:21:56 +00:00
|
|
|
}
|
2018-07-29 04:17:17 +00:00
|
|
|
}
|
2021-05-02 08:47:19 +00:00
|
|
|
return nil
|
2018-07-29 04:17:17 +00:00
|
|
|
}
|
2019-05-09 06:58:55 +00:00
|
|
|
|
2021-05-02 08:47:19 +00:00
|
|
|
func tickLoop(thumbChan chan bool) error {
|
|
|
|
tl := c.NewTickLoop()
|
|
|
|
TickLoop = tl
|
|
|
|
if e := deferredDailies(); e != nil {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
if e := c.StartupTasks(); e != nil {
|
|
|
|
return e
|
2019-12-31 21:57:54 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 08:47:19 +00:00
|
|
|
tick := func(name string, tasks []func() error) error {
|
|
|
|
if c.StartTick() {
|
2019-05-09 06:58:55 +00:00
|
|
|
return nil
|
|
|
|
}
|
2021-05-02 08:47:19 +00:00
|
|
|
if e := runHook("before_" + name + "_tick"); e != nil {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
if e := c.RunTasks(tasks); e != nil {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
return runHook("after_" + name + "_tick")
|
2019-05-09 06:58:55 +00:00
|
|
|
}
|
2019-12-31 21:57:54 +00:00
|
|
|
|
2021-05-02 08:47:19 +00:00
|
|
|
tl.HalfSecf = func() error {
|
|
|
|
return tick("half_second", c.ScheduledHalfSecondTasks)
|
|
|
|
}
|
|
|
|
// TODO: Automatically lock topics, if they're really old, and the associated setting is enabled.
|
|
|
|
// TODO: Publish scheduled posts.
|
|
|
|
tl.FifteenMinf = func() error {
|
|
|
|
return tick("fifteen_minute", c.ScheduledFifteenMinuteTasks)
|
2020-01-04 05:30:25 +00:00
|
|
|
}
|
2021-05-02 08:47:19 +00:00
|
|
|
// TODO: Handle the instance going down a lot better
|
|
|
|
// TODO: Handle the daily clean-up.
|
|
|
|
tl.Dayf = func() error {
|
|
|
|
if c.StartTick() {
|
|
|
|
return nil
|
2019-06-05 04:57:10 +00:00
|
|
|
}
|
2021-05-02 08:47:19 +00:00
|
|
|
return c.Dailies()
|
2019-06-05 04:57:10 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 08:47:19 +00:00
|
|
|
tl.Secf = func() (e error) {
|
|
|
|
if c.StartTick() {
|
|
|
|
return nil
|
2020-01-02 21:52:41 +00:00
|
|
|
}
|
2021-05-02 08:47:19 +00:00
|
|
|
if e = runHook("before_second_tick"); e != nil {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
go func() { thumbChan <- true }()
|
|
|
|
if e = c.RunTasks(c.ScheduledSecondTasks); e != nil {
|
|
|
|
return e
|
2019-05-09 06:58:55 +00:00
|
|
|
}
|
2020-01-02 05:28:36 +00:00
|
|
|
|
2021-05-02 08:47:19 +00:00
|
|
|
// TODO: Stop hard-coding this
|
|
|
|
if e = c.HandleExpiredScheduledGroups(); e != nil {
|
|
|
|
return e
|
2020-01-02 09:49:34 +00:00
|
|
|
}
|
2021-05-02 08:47:19 +00:00
|
|
|
|
|
|
|
// TODO: Handle delayed moderation tasks
|
|
|
|
|
|
|
|
// Sync with the database, if there are any changes
|
|
|
|
if e = c.HandleServerSync(); e != nil {
|
|
|
|
return e
|
2020-01-02 05:28:36 +00:00
|
|
|
}
|
2019-05-09 06:58:55 +00:00
|
|
|
|
2021-05-02 08:47:19 +00:00
|
|
|
// TODO: Manage the TopicStore, UserStore, and ForumStore
|
|
|
|
// TODO: Alert the admin, if CPU usage, RAM usage, or the number of posts in the past second are too high
|
|
|
|
// TODO: Clean-up alerts with no unread matches which are over two weeks old. Move this to a 24 hour task?
|
|
|
|
// TODO: Rescan the static files for changes
|
|
|
|
return runHook("after_second_tick")
|
2019-12-31 21:57:54 +00:00
|
|
|
}
|
2019-05-09 06:58:55 +00:00
|
|
|
|
2021-05-02 08:47:19 +00:00
|
|
|
tl.Hourf = func() error {
|
|
|
|
if c.StartTick() {
|
|
|
|
return nil
|
2019-12-31 21:57:54 +00:00
|
|
|
}
|
2021-05-02 08:47:19 +00:00
|
|
|
if e := runHook("before_hour_tick"); e != nil {
|
|
|
|
return e
|
2019-12-31 21:57:54 +00:00
|
|
|
}
|
2019-05-09 06:58:55 +00:00
|
|
|
|
2021-05-02 08:47:19 +00:00
|
|
|
jsToken, e := c.GenerateSafeString(80)
|
|
|
|
if e != nil {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
c.JSTokenBox.Store(jsToken)
|
2021-03-23 10:21:56 +00:00
|
|
|
|
2021-05-02 08:47:19 +00:00
|
|
|
c.OldSessionSigningKeyBox.Store(c.SessionSigningKeyBox.Load().(string)) // TODO: We probably don't need this type conversion
|
|
|
|
sessionSigningKey, e := c.GenerateSafeString(80)
|
2021-04-08 00:14:24 +00:00
|
|
|
if e != nil {
|
2021-05-02 08:47:19 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
c.SessionSigningKeyBox.Store(sessionSigningKey)
|
|
|
|
|
|
|
|
if e = c.RunTasks(c.ScheduledHourTasks); e != nil {
|
|
|
|
return e
|
2019-12-31 21:57:54 +00:00
|
|
|
}
|
2021-05-02 08:47:19 +00:00
|
|
|
return runHook("after_hour_tick")
|
2019-05-09 06:58:55 +00:00
|
|
|
}
|
2021-05-02 08:47:19 +00:00
|
|
|
|
|
|
|
go tl.Loop()
|
|
|
|
|
|
|
|
return nil
|
2020-01-02 05:28:36 +00:00
|
|
|
}
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
|
|
|
|
func sched() error {
|
2021-04-08 00:14:24 +00:00
|
|
|
ws := errors.WithStack
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
schedStr, err := c.Meta.Get("sched")
|
|
|
|
// TODO: Report this error back correctly...
|
|
|
|
if err != nil && err != sql.ErrNoRows {
|
2021-04-08 00:14:24 +00:00
|
|
|
return ws(err)
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if schedStr == "recalc" {
|
|
|
|
log.Print("Cleaning up orphaned data.")
|
|
|
|
|
|
|
|
count, err := c.Recalc.Replies()
|
|
|
|
if err != nil {
|
2021-04-08 00:14:24 +00:00
|
|
|
return ws(err)
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
}
|
|
|
|
log.Printf("Deleted %d orphaned replies.", count)
|
|
|
|
|
2020-03-09 03:51:44 +00:00
|
|
|
count, err = c.Recalc.Forums()
|
|
|
|
if err != nil {
|
2021-04-08 00:14:24 +00:00
|
|
|
return ws(err)
|
2020-03-09 03:51:44 +00:00
|
|
|
}
|
|
|
|
log.Printf("Recalculated %d forum topic counts.", count)
|
|
|
|
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
count, err = c.Recalc.Subscriptions()
|
|
|
|
if err != nil {
|
2021-04-08 00:14:24 +00:00
|
|
|
return ws(err)
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
}
|
|
|
|
log.Printf("Deleted %d orphaned subscriptions.", count)
|
|
|
|
|
|
|
|
count, err = c.Recalc.ActivityStream()
|
|
|
|
if err != nil {
|
2021-04-08 00:14:24 +00:00
|
|
|
return ws(err)
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
}
|
|
|
|
log.Printf("Deleted %d orphaned activity stream items.", count)
|
|
|
|
|
|
|
|
err = c.Recalc.Users()
|
|
|
|
if err != nil {
|
2021-04-08 00:14:24 +00:00
|
|
|
return ws(err)
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
}
|
|
|
|
log.Print("Recalculated user post stats.")
|
|
|
|
|
|
|
|
count, err = c.Recalc.Attachments()
|
|
|
|
if err != nil {
|
2021-04-08 00:14:24 +00:00
|
|
|
return ws(err)
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
}
|
|
|
|
log.Printf("Deleted %d orphaned attachments.", count)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|