@task(rate_limit='50/m')
@write
def update_denorm(*pairs, **kw):
 log.info(('[%s@%s] Updating review denorms.' % (len(pairs), update_denorm.rate_limit)))
 for (addon, user) in pairs:
  reviews = list(Review.without_replies.all().no_cache().filter(addon=addon, user=user).order_by('created'))
  if (not reviews):
   continue
  for (idx, review) in enumerate(reviews):
   review.previous_count = idx
   review.is_latest = False
  reviews[(-1)].is_latest = True
  for review in reviews:
   review.save()

@ task ( rate_limit = '50/m' ) @ write def update_denorm ( * pairs , ** kw ) : log . info ( ( '[%s@%s] Updating review denorms.' % ( len ( pairs ) , update_denorm . rate_limit ) ) ) for ( addon , user ) in pairs : reviews = list ( Review . without_replies . all ( ) . no_cache ( ) . filter ( addon = addon , user = user ) . order_by ( 'created' ) ) if ( not reviews ) : continue for ( idx , review ) in enumerate ( reviews ) : review . previous_count = idx review . is_latest = False reviews [ ( - 1 ) ] . is_latest = True for review in reviews : review . save ( )
takes a bunch of pairs and sets the denormalized fields for all reviews matching that pair .