From 3339d9d3d7ca08852bb430fee3aa8ac82a9cfc9f Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 4 Mar 2024 00:51:55 +0100 Subject: [PATCH] Preallocate memory when exporting to OPML This should marginally increase performance when export a large amount of feeds to OPML. --- internal/reader/opml/handler.go | 2 +- internal/reader/opml/serializer.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/reader/opml/handler.go b/internal/reader/opml/handler.go index c3e972b9..9257d354 100644 --- a/internal/reader/opml/handler.go +++ b/internal/reader/opml/handler.go @@ -23,7 +23,7 @@ func (h *Handler) Export(userID int64) (string, error) { return "", err } - var subscriptions SubcriptionList + subscriptions := make(SubcriptionList, 0, len(feeds)) for _, feed := range feeds { subscriptions = append(subscriptions, &Subcription{ Title: feed.Title, diff --git a/internal/reader/opml/serializer.go b/internal/reader/opml/serializer.go index b1638e4c..2ecccbed 100644 --- a/internal/reader/opml/serializer.go +++ b/internal/reader/opml/serializer.go @@ -38,14 +38,14 @@ func convertSubscriptionsToOPML(subscriptions SubcriptionList) *opmlDocument { opmlDocument.Header.DateCreated = time.Now().Format("Mon, 02 Jan 2006 15:04:05 MST") groupedSubs := groupSubscriptionsByFeed(subscriptions) - var categories []string + categories := make([]string, 0, len(groupedSubs)) for k := range groupedSubs { categories = append(categories, k) } sort.Strings(categories) for _, categoryName := range categories { - category := opmlOutline{Text: categoryName} + category := opmlOutline{Text: categoryName, Outlines: make(opmlOutlineCollection, 0, len(groupedSubs[categoryName]))} for _, subscription := range groupedSubs[categoryName] { category.Outlines = append(category.Outlines, opmlOutline{ Title: subscription.Title,