mirror of https://github.com/gophish/gophish
Changed caching to only load the fields required for generating the campaign emails.
parent
bcec68e2a9
commit
cfaa789632
|
@ -362,6 +362,38 @@ func GetCampaignSummary(id int64, uid int64) (CampaignSummary, error) {
|
|||
return cs, nil
|
||||
}
|
||||
|
||||
// GetCampaignMailContext returns a campaign object with just the relevant
|
||||
// data needed to generate and send emails. This includes the top-level
|
||||
// metadata, the template, and the sending profile.
|
||||
//
|
||||
// This should only ever be used if you specifically want this lightweight
|
||||
// context, since it returns a non-standard campaign object.
|
||||
// ref: #1726
|
||||
func GetCampaignMailContext(id int64, uid int64) (Campaign, error) {
|
||||
c := Campaign{}
|
||||
err := db.Where("id = ?", id).Where("user_id = ?", uid).Find(&c).Error
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
err = db.Table("smtp").Where("id=?", c.SMTPId).Find(&c.SMTP).Error
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
err = db.Where("smtp_id=?", c.SMTP.Id).Find(&c.SMTP.Headers).Error
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
return c, err
|
||||
}
|
||||
err = db.Table("templates").Where("id=?", c.TemplateId).Find(&c.Template).Error
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
err = db.Where("template_id=?", c.Template.Id).Find(&c.Template.Attachments).Error
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
return c, err
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// GetCampaign returns the campaign, if it exists, specified by the given id and user_id.
|
||||
func GetCampaign(id int64, uid int64) (Campaign, error) {
|
||||
c := Campaign{}
|
||||
|
|
|
@ -132,7 +132,7 @@ func (m *MailLog) Success() error {
|
|||
func (m *MailLog) GetDialer() (mailer.Dialer, error) {
|
||||
c := m.cachedCampaign
|
||||
if c == nil {
|
||||
campaign, err := GetCampaign(m.CampaignId, m.UserId)
|
||||
campaign, err := GetCampaignMailContext(m.CampaignId, m.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ func (m *MailLog) Generate(msg *gomail.Message) error {
|
|||
}
|
||||
c := m.cachedCampaign
|
||||
if c == nil {
|
||||
campaign, err := GetCampaign(m.CampaignId, m.UserId)
|
||||
campaign, err := GetCampaignMailContext(m.CampaignId, m.UserId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ func (w *DefaultWorker) processCampaigns(t time.Time) error {
|
|||
// generate the message (ref #1726)
|
||||
c, ok := campaignCache[m.CampaignId]
|
||||
if !ok {
|
||||
c, err = models.GetCampaign(m.CampaignId, m.UserId)
|
||||
c, err = models.GetCampaignMailContext(m.CampaignId, m.UserId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue