فهرست منبع

perf(notifications): exit early if notifications are disabled

ayn2op 9 ماه پیش
والد
کامیت
b243e2f7f1
1فایلهای تغییر یافته به همراه8 افزوده شده و 5 حذف شده
  1. 8 5
      internal/notifications/notifications.go

+ 8 - 5
internal/notifications/notifications.go

@@ -16,9 +16,12 @@ import (
 )
 
 func Notify(state *ningen.State, msg *gateway.MessageCreateEvent, cfg *config.Config) error {
+	if !cfg.Notifications.Enabled || cfg.Status == discord.DoNotDisturbStatus {
+		return nil
+	}
+
 	mentions := state.MessageMentions(&msg.Message)
-	// Only display notification if enabled and unmuted
-	if !cfg.Notifications.Enabled || mentions == 0 || cfg.Status == discord.DoNotDisturbStatus {
+	if mentions == 0 {
 		return nil
 	}
 
@@ -87,11 +90,11 @@ func getCachedProfileImage(avatarHash discord.Hash, url string) (string, error)
 		return path, nil
 	}
 
-	image, err := os.Create(path)
+	file, err := os.Create(path)
 	if err != nil {
 		return "", err
 	}
-	defer image.Close()
+	defer file.Close()
 
 	resp, err := http.Get(url)
 	if err != nil {
@@ -99,7 +102,7 @@ func getCachedProfileImage(avatarHash discord.Hash, url string) (string, error)
 	}
 	defer resp.Body.Close()
 
-	if _, err := io.Copy(image, resp.Body); err != nil {
+	if _, err := io.Copy(file, resp.Body); err != nil {
 		return "", err
 	}