def index_installed_daily(ids, **kw): """ Takes a list of Installed ids and uses its addon and date fields to index stats for that day. ids -- ids of mkt.webapps.Installed objects """ from mkt.webapps.models import Installed index = kw.get('index', Installed._get_index()) es = amo.search.get_es() # Get Installed's qs = (Installed.objects.filter(id__in=set(ids)). order_by('-created').values('addon', 'created')) log.info('[%s] Indexing %s installed counts for daily stats.' % (qs[0]['created'], len(qs))) addons_dates = defaultdict(lambda: defaultdict(dict)) for installed in qs: addon = installed['addon'] date = installed['created'].strftime('%Y%m%d') try: if not date in addons_dates[addon]: key = ord_word('ins' + str(addon) + str(date)) data = search.get_installed_daily(installed) for index in get_indices(index): if not already_indexed(Installed, data, index): Installed.index(data, bulk=True, id=key, index=index) addons_dates[addon][date] = 0 es.flush_bulk(forced=True) except Exception, exc: index_installed_daily.retry(args=[ids], exc=exc, **kw) raise