mirror of https://github.com/gophish/gophish
Removing unneeded query to improve group performance.
As mentioned in #1702, the query in `insertTargetIntoGroup` isn't needed, since both instances where it's used we already know that the target isn't in the group. This means it's safe to remove that query, improving performance dramatically. Before: ``` BenchmarkPostGroup100-4 81 12629754 ns/op 2989993 B/op 52918 allocs/op BenchmarkPostGroup1000-4 6 189527792 ns/op 29891818 B/op 528082 allocs/op BenchmarkPostGroup10000-4 1 6203645806 ns/op 299253648 B/op 5282859 allocs/op BenchmarkPutGroup100-4 100 10221833 ns/op 2589165 B/op 46078 allocs/op BenchmarkPutGroup1000-4 7 162692432 ns/op 25812440 B/op 458425 allocs/op BenchmarkPutGroup10000-4 1 7596445084 ns/op 260385808 B/op 4581569 allocs/op ``` After: ``` BenchmarkPostGroup100-4 133 8848973 ns/op 2354605 B/op 42322 allocs/op BenchmarkPostGroup1000-4 9 112557410 ns/op 23549206 B/op 422184 allocs/op BenchmarkPostGroup10000-4 1 3414209403 ns/op 235635952 B/op 4222090 allocs/op BenchmarkPutGroup100-4 147 8094333 ns/op 2271297 B/op 40777 allocs/op BenchmarkPutGroup1000-4 9 125092124 ns/op 22635067 B/op 405421 allocs/op BenchmarkPutGroup10000-4 1 5712591900 ns/op 228592920 B/op 4051316 allocs/op ```pull/1722/head
parent
91d798336f
commit
546da4ee7d
|
@ -327,14 +327,11 @@ func insertTargetIntoGroup(tx *gorm.DB, t Target, gid int64) error {
|
||||||
}).Error(err)
|
}).Error(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = tx.Where("group_id=? and target_id=?", gid, t.Id).Find(&GroupTarget{}).Error
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
err = tx.Save(&GroupTarget{GroupId: gid, TargetId: t.Id}).Error
|
err = tx.Save(&GroupTarget{GroupId: gid, TargetId: t.Id}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
"email": t.Email,
|
"email": t.Email,
|
||||||
|
|
Loading…
Reference in New Issue