gorm: The performance for update is bad!
I test a update as follow:
start := time.Now()
if val, ok := value.(*data); ok {
ps.Model(val.Model).Updates(val.Data)
}
fmt.Printf("111111111111111111The time save take:%v\n", time.Since(start))
The sql take just 1.83 ms.
[2015-12-28 21:48:58] [1.83ms] UPDATE `profile` SET `nick_name` = 'xxx', `exchanged_times` = '0', `exchanged_for_other_currency` = '0', `gem` = '0', `currency` = '100', `contact` = '', `purchased_for_othertimes` = '0', `max_gem` = '0', `signature` = '', `is_active` = 'true', `charged_times` = '0', `purchased_gem` = '0', `exchanged_for_othertimes` = '0', `purchased_times` = '0', `gender` = '0', `charged_for_othertimes` = '0', `charged_for_other_money` = '0', `charged_money` = '0', `exchanged_currency` = '0', `purchased_for_other_gem` = '0', `max_currency` = '100', `privilege_end_time` = '1984-08-07T07:45:00+08:00', `taked_currency` = '0', `avatar_url` = '5', `privilege_level` = '0', `bank_currency` = '0', `created_at` = '2015-12-28T21:48:57+08:00' WHERE (`player_id` = '1024')
but the ps.Model(val.Model).Updates(val.Data) take 41ms.
111111111111111111The time save take:41.247981ms
why? and how to refine? @jinzhu
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 19 (6 by maintainers)
@jinzhu I test on ubuntu again. there is no changes! and i update the test script above! And i found that
problem is db.LogMode(true),
func (s *DB) print(v …interface{}) { s.logger.Print(v…) } cost too much time @jinzhu @zj8487 ,db.LogMode should be set false in produciton mode
@zj8487 @cristian-sima
Had same problem with second SQL query (SELECT after INSERT). Cured by the following:
gorm.DefaultCallback.Create().Remove("gorm:force_reload_after_create")