From 31ac62f410361d9c6b1f27c36c2ff8cd8309653a Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 29 Feb 2024 13:07:36 +0100 Subject: [PATCH] Don't compute reading-time when unused If the user doesn't display reading times, there is no need to compute them. This should speed things up a bit, since `whatlanggo.Detect` is abysmally slow. --- internal/api/entry.go | 4 +++- internal/reader/processor/processor.go | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/api/entry.go b/internal/api/entry.go index 2af2b3c7..f8d1ce69 100644 --- a/internal/api/entry.go +++ b/internal/api/entry.go @@ -275,7 +275,9 @@ func (h *handler) updateEntry(w http.ResponseWriter, r *http.Request) { } entryUpdateRequest.Patch(entry) - entry.ReadingTime = readingtime.EstimateReadingTime(entry.Content, user.DefaultReadingSpeed, user.CJKReadingSpeed) + if user.ShowReadingTime { + entry.ReadingTime = readingtime.EstimateReadingTime(entry.Content, user.DefaultReadingSpeed, user.CJKReadingSpeed) + } if err := h.store.UpdateEntryTitleAndContent(entry); err != nil { json.ServerError(w, r, err) diff --git a/internal/reader/processor/processor.go b/internal/reader/processor/processor.go index 0656670f..7c1b6b1d 100644 --- a/internal/reader/processor/processor.go +++ b/internal/reader/processor/processor.go @@ -204,7 +204,9 @@ func ProcessEntryWebPage(feed *model.Feed, entry *model.Entry, user *model.User) if content != "" { entry.Content = content - entry.ReadingTime = readingtime.EstimateReadingTime(entry.Content, user.DefaultReadingSpeed, user.CJKReadingSpeed) + if user.ShowReadingTime { + entry.ReadingTime = readingtime.EstimateReadingTime(entry.Content, user.DefaultReadingSpeed, user.CJKReadingSpeed) + } } rewrite.Rewriter(websiteURL, entry, entry.Feed.RewriteRules) @@ -282,7 +284,9 @@ func updateEntryReadingTime(store *storage.Storage, feed *model.Feed, entry *mod } // Handle YT error case and non-YT entries. if entry.ReadingTime == 0 { - entry.ReadingTime = readingtime.EstimateReadingTime(entry.Content, user.DefaultReadingSpeed, user.CJKReadingSpeed) + if user.ShowReadingTime { + entry.ReadingTime = readingtime.EstimateReadingTime(entry.Content, user.DefaultReadingSpeed, user.CJKReadingSpeed) + } } }