Batch update records in Grails

Posted by UltraVi01 on Stack Overflow See other posts from Stack Overflow or by UltraVi01
Published on 2010-05-28T13:05:19Z Indexed on 2010/05/30 15:22 UTC
Read the original article Hit count: 308

Filed under:
|
|

I have to calculate a "total" for each user based on individual actions -- that is, a User hasMany Actions and each Action has a point. So I need to basically get a sum of all the points on all the actions.

Actions are added and subtracted regularly. Since this can be a rather heavy operation, it's not feasible that I execute the "total" each time I need it. Therefore, I am thinking of running the operation once a day for each user and storing the total points on the User as an int.

Because I have thousands of users, I am trying to figure out the best way to do this. Should I basically iterate through all the users and call User.save() each time, or is there some kind of batch update mechanism I can use in Grails / GORM?

© Stack Overflow or respective owner

Related posts about grails

Related posts about groovy