aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jvoisin <julien.voisin@dustri.org> 2024-02-24 14:12:07 +0100
committerGravatar Frédéric Guillot <f@miniflux.net> 2024-02-24 20:22:53 -0800
commitb48ad6dbfb31ce113313c3120fd98a19522da699 (patch)
treed436183fccd7e51d0c6e624bf0f61adb915e8f2c
parent2be5051b19a397eff187b2f458b0c8aeece4e83b (diff)
downloadv2-b48ad6dbfb31ce113313c3120fd98a19522da699.tar.gz
v2-b48ad6dbfb31ce113313c3120fd98a19522da699.tar.zst
v2-b48ad6dbfb31ce113313c3120fd98a19522da699.zip
Make use of go≥1.21 slices package instead of hand-rolled loops
This makes the code a tad smaller, moderner, and maybe even marginally faster, yay!
-rw-r--r--internal/reader/processor/processor.go21
-rw-r--r--internal/template/functions.go8
2 files changed, 9 insertions, 20 deletions
diff --git a/internal/reader/processor/processor.go b/internal/reader/processor/processor.go
index 8a5bdf56..9068d4c2 100644
--- a/internal/reader/processor/processor.go
+++ b/internal/reader/processor/processor.go
@@ -8,6 +8,7 @@ import (
"fmt"
"log/slog"
"regexp"
+ "slices"
"strconv"
"time"
@@ -115,13 +116,9 @@ func ProcessFeedEntries(store *storage.Storage, feed *model.Feed, user *model.Us
func isBlockedEntry(feed *model.Feed, entry *model.Entry) bool {
if feed.BlocklistRules != "" {
- var containsBlockedTag bool = false
- for _, tag := range entry.Tags {
- if matchField(feed.BlocklistRules, tag) {
- containsBlockedTag = true
- break
- }
- }
+ containsBlockedTag := slices.ContainsFunc(entry.Tags, func(tag string) bool {
+ return matchField(feed.BlocklistRules, tag)
+ })
if matchField(feed.BlocklistRules, entry.URL) || matchField(feed.BlocklistRules, entry.Title) || matchField(feed.BlocklistRules, entry.Author) || containsBlockedTag {
slog.Debug("Blocking entry based on rule",
@@ -140,13 +137,9 @@ func isBlockedEntry(feed *model.Feed, entry *model.Entry) bool {
func isAllowedEntry(feed *model.Feed, entry *model.Entry) bool {
if feed.KeeplistRules != "" {
- var containsAllowedTag bool = false
- for _, tag := range entry.Tags {
- if matchField(feed.KeeplistRules, tag) {
- containsAllowedTag = true
- break
- }
- }
+ containsAllowedTag := slices.ContainsFunc(entry.Tags, func(tag string) bool {
+ return matchField(feed.KeeplistRules, tag)
+ })
if matchField(feed.KeeplistRules, entry.URL) || matchField(feed.KeeplistRules, entry.Title) || matchField(feed.KeeplistRules, entry.Author) || containsAllowedTag {
slog.Debug("Allow entry based on rule",
diff --git a/internal/template/functions.go b/internal/template/functions.go
index ef3ffd37..2db98420 100644
--- a/internal/template/functions.go
+++ b/internal/template/functions.go
@@ -8,6 +8,7 @@ import (
"html/template"
"math"
"net/mail"
+ "slices"
"strings"
"time"
@@ -72,12 +73,7 @@ func (f *funcMap) Map() template.FuncMap {
return link
},
"mustBeProxyfied": func(mediaType string) bool {
- for _, t := range config.Opts.ProxyMediaTypes() {
- if t == mediaType {
- return true
- }
- }
- return false
+ return slices.Contains(config.Opts.ProxyMediaTypes(), mediaType)
},
"domain": func(websiteURL string) string {
return urllib.Domain(websiteURL)