Improve memory efficiency of noticesToBeSent by mapping pointers instead of WidNotice structs
This commit is contained in:
parent
295ceec3de
commit
9b00959fdb
4 changed files with 8 additions and 7 deletions
2
mail.go
2
mail.go
|
@ -49,7 +49,7 @@ type SmtpSettings struct {
|
|||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
func sendNotices(recipient string, notices []WidNotice, template MailTemplate, auth smtp.Auth, smtpConfig SmtpSettings, cache *map[string][]byte) error {
|
||||
func sendNotices(recipient string, notices []*WidNotice, template MailTemplate, auth smtp.Auth, smtpConfig SmtpSettings, cache *map[string][]byte) error {
|
||||
logger.debug("Generating and sending mails for recipient " + recipient + " ...")
|
||||
cacheHits := 0
|
||||
cacheMisses := 0
|
||||
|
|
9
main.go
9
main.go
|
@ -121,16 +121,17 @@ func main() {
|
|||
if len(newNotices) > 0 {
|
||||
logger.info("Sending email notifications ...")
|
||||
// mail recipient : pointer to slice of wid notices to be sent
|
||||
noticesToBeSent := map[string][]WidNotice{}
|
||||
noticesToBeSent := map[string][]*WidNotice{}
|
||||
recipientsNotified := 0
|
||||
var err error
|
||||
for _, l := range *config.Lists {
|
||||
// Filter notices for this list
|
||||
for _, f := range l.Filter {
|
||||
for _, n := range f.filter(newNotices) {
|
||||
np := &n
|
||||
for _, r := range l.Recipients {
|
||||
if !noticeSliceContains(noticesToBeSent[r], n) {
|
||||
noticesToBeSent[r] = append(noticesToBeSent[r], n)
|
||||
if !noticeSliceContains(noticesToBeSent[r], np) {
|
||||
noticesToBeSent[r] = append(noticesToBeSent[r], np)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +139,7 @@ func main() {
|
|||
}
|
||||
for r, notices := range noticesToBeSent {
|
||||
// sort by publish date
|
||||
slices.SortFunc(notices, func(a WidNotice, b WidNotice) int {
|
||||
slices.SortFunc(notices, func(a *WidNotice, b *WidNotice) int {
|
||||
if a.Published == b.Published {
|
||||
return 0
|
||||
} else if a.Published.After(b.Published) {
|
||||
|
|
|
@ -25,7 +25,7 @@ type WidNotice struct {
|
|||
PortalUrl string
|
||||
}
|
||||
|
||||
func noticeSliceContains(notices []WidNotice, notice WidNotice) bool {
|
||||
func noticeSliceContains(notices []*WidNotice, notice *WidNotice) bool {
|
||||
for _, x := range notices {
|
||||
if x.Uuid == notice.Uuid {
|
||||
return true
|
||||
|
|
|
@ -33,7 +33,7 @@ Sent by WidNotifier {{ .WidNotifierVersion }}
|
|||
`
|
||||
|
||||
type TemplateData struct {
|
||||
WidNotice
|
||||
*WidNotice
|
||||
WidNotifierVersion string
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue