From 2d98fcffdf895a6a23a34e2bfc0b1430488f2e0e Mon Sep 17 00:00:00 2001 From: Max Magorsch Date: Fri, 19 Jun 2020 18:33:21 +0200 Subject: Speed up the /lists page Signed-off-by: Max Magorsch --- pkg/importer/utils.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pkg/importer') diff --git a/pkg/importer/utils.go b/pkg/importer/utils.go index c2d38fc..1af34ed 100644 --- a/pkg/importer/utils.go +++ b/pkg/importer/utils.go @@ -28,6 +28,7 @@ func importMail(name, path, maildirPath string) { Body: getBody(m.Header, m.Body), Date: getDate(m.Header), Lists: getLists(m.Header), + List: getListName(path), Comment: "", Hidden: false, } @@ -116,6 +117,12 @@ func getLists(header mail.Header) []string { return lists } +func getListName(path string) string { + listName := strings.ReplaceAll(path, config.MailDirPath() + ".", "") + listName = strings.Split(listName, "/")[0] + return listName +} + func insertMessage(message models.Message) error { _, err := database.DBCon.Model(&message). Value("tsv_subject", "to_tsvector(?)", message.GetSubject()). @@ -127,7 +134,7 @@ func insertMessage(message models.Message) error { func isPublicList(path string) bool { for _, publicList := range config.AllPublicMailingLists(){ - if strings.HasPrefix(path, config.MailDirPath() + "." + publicList + "/") { + if publicList == getListName(path) { return true } } -- cgit v1.2.3-18-g5258