aboutsummaryrefslogtreecommitdiff
path: root/userapi/userapi.go
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-03-03 16:45:06 +0000
committerGitHub <noreply@github.com>2022-03-03 16:45:06 +0000
commit5592322e13d0bf741130425079e37979f7637564 (patch)
tree10f52efd3a33f520085d643c1498c9407f9b969f /userapi/userapi.go
parentc44029f269d0b17102dbbf31e50669c7c93fe50e (diff)
Clean old notifications regularly (#2244)
* Clean old notifications regularly We'll keep highlights for a month and non-highlights for a day, to stop the `userapi_notifications` table from growing indefinitely. We'll also allow storing events even if no pushers are present, because apparently Element Web expects to work that way. * Fix the milliseconds * Use process context * Update sytest lists * Fix build issue
Diffstat (limited to 'userapi/userapi.go')
-rw-r--r--userapi/userapi.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/userapi/userapi.go b/userapi/userapi.go
index 8dbc095f..251a4eda 100644
--- a/userapi/userapi.go
+++ b/userapi/userapi.go
@@ -15,6 +15,8 @@
package userapi
import (
+ "time"
+
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/internal/pushgateway"
keyapi "github.com/matrix-org/dendrite/keyserver/api"
@@ -79,5 +81,15 @@ func NewInternalAPI(
logrus.WithError(err).Panic("failed to start user API streamed event consumer")
}
+ var cleanOldNotifs func()
+ cleanOldNotifs = func() {
+ logrus.Infof("Cleaning old notifications")
+ if err := db.DeleteOldNotifications(base.Context()); err != nil {
+ logrus.WithError(err).Error("Failed to clean old notifications")
+ }
+ time.AfterFunc(time.Hour, cleanOldNotifs)
+ }
+ time.AfterFunc(time.Minute, cleanOldNotifs)
+
return userAPI
}