2
0
mirror of https://github.com/carlostrub/sisyphus synced 2024-10-31 09:20:15 +00:00

improve memory footprint

This commit is contained in:
Carlo Strub 2017-09-17 00:56:17 +02:00
parent 77fa162ee0
commit bbee193679
5 changed files with 42 additions and 1 deletions

View File

@ -6,6 +6,9 @@
- Converted the entire app to a [Twelve-Factor App](https://12factor.net/). - Converted the entire app to a [Twelve-Factor App](https://12factor.net/).
This has consequences in how you launch it, i.e. use environment variables This has consequences in how you launch it, i.e. use environment variables
instead of flags. instead of flags.
- The interval between learning periods can be set at runtime now.
- Unload mail content after classification and learning, should reduce memory
requirements.
## Fixed ## Fixed
- Only permit unicode characters of bitsize larger than 2, this guarantees we - Only permit unicode characters of bitsize larger than 2, this guarantees we

View File

@ -178,7 +178,9 @@ func (m *Mail) Classify(db *bolt.DB, dir Maildir) (err error) {
}).Info("Moved to Junk folder") }).Info("Moved to Junk folder")
} }
return nil err = m.Unload(dir)
return err
} }
// Junk returns true if the wordlist is classified as a junk mail using Bayes' // Junk returns true if the wordlist is classified as a junk mail using Bayes'

View File

@ -98,6 +98,11 @@ func (m *Mail) Learn(db *bolt.DB, dir Maildir) (err error) {
// Update the statistics counter // Update the statistics counter
err = m.learnStatistics(db) err = m.learnStatistics(db)
if err != nil {
return err
}
err = m.Unload(dir)
return err return err

View File

@ -125,6 +125,15 @@ func (m *Mail) Load(dir Maildir) (err error) {
return nil return nil
} }
// Unload removes a mail's subject and body from the internal cache
func (m *Mail) Unload(dir Maildir) (err error) {
m.Subject = nil
m.Body = nil
return nil
}
func trimStringFromBase64(s string) string { func trimStringFromBase64(s string) string {
if idx := strings.Index(s, "Content-Transfer-Encoding: base64"); idx != -1 { if idx := strings.Index(s, "Content-Transfer-Encoding: base64"); idx != -1 {
return s[:idx-1] return s[:idx-1]

View File

@ -123,6 +123,28 @@ var _ = Describe("Mail", func() {
Junk: true, Junk: true,
})) }))
}) })
It("Unload mail content from struct", func() {
m := s.Mail{
Key: "1488226337.M327822P8269.mail.carlostrub.ch,S=3620,W=3730",
Subject: nil,
Body: nil,
Junk: true,
}
err := m.Load("test/Maildir")
Ω(err).ShouldNot(HaveOccurred())
err = m.Unload("test/Maildir")
Ω(err).ShouldNot(HaveOccurred())
Ω(m).Should(Equal(
s.Mail{
Key: "1488226337.M327822P8269.mail.carlostrub.ch,S=3620,W=3730",
Subject: nil,
Body: nil,
Junk: true,
}))
})
It("Fail if Subject has already content", func() { It("Fail if Subject has already content", func() {
st := "test" st := "test"
m := s.Mail{ m := s.Mail{