commit 138b774bb9f1e813a24ca92c71ca203436098ad1
parent f241f2fba828fa1d976fb8c8120c95f3e6a10dda
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sat, 30 Dec 2023 21:48:53 -0500
cleanup
Diffstat:
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/pkg/web/handlers/chat.go b/pkg/web/handlers/chat.go
@@ -139,7 +139,7 @@ func handleLogoutPost(c echo.Context, room database.ChatRoom) error {
func handleTutorialPost(db *database.DkfDB, c echo.Context, data chatData, authUser *database.User) error {
if authUser.ChatTutorial < 3 && time.Since(authUser.ChatTutorialTime) >= time.Duration(data.TutoSecs)*time.Second {
authUser.ChatTutorial++
- authUser.DoSave(db)
+ db.DB().Model(authUser).Update("chat_tutorial", authUser.ChatTutorial)
}
return hutils.RedirectReferer(c)
}
diff --git a/pkg/web/middlewares/middlewares.go b/pkg/web/middlewares/middlewares.go
@@ -286,14 +286,14 @@ func NewRateLimitV[K comparable, V any](defaultExpiration time.Duration) *RateLi
}
}
-func (l *RateLimit[K, V]) Clb(k K, clb func()) {
+func (l *RateLimit[K, V]) RateLimit(k K, clb func()) {
if !l.cache.Has(k) {
clb()
l.cache.SetD(k, l.value)
}
}
-func (l *RateLimit[K, V]) ClbV(k K, clb func() (V, error)) (V, bool, error) {
+func (l *RateLimit[K, V]) RateLimitV(k K, clb func() (V, error)) (V, bool, error) {
var err error
if !l.cache.Has(k) {
l.value, err = clb()
@@ -327,7 +327,7 @@ func IsAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
c.Response().Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
- lastSeenRL.Clb(user.ID, func() {
+ lastSeenRL.RateLimit(user.ID, func() {
now := time.Now()
db.DB().Exec("UPDATE users SET last_seen_at = ?, updated_at = ? WHERE id = ?", now, now, int64(user.ID))
})