@cronjobs.register
def collection_subscribers():
 log.debug('Starting collection subscriber update...')
 if (not waffle.switch_is_active('local-statistics-processing')):
  return False
 cursor = connection.cursor()
 cursor.execute('\n        UPDATE collections SET weekly_subscribers = 0, monthly_subscribers = 0\n    ')
 cursor.execute('\n        UPDATE collections AS c\n        INNER JOIN (\n            SELECT\n                COUNT(collection_id) AS count,\n                collection_id\n            FROM collection_subscriptions\n            WHERE created >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)\n            GROUP BY collection_id\n        ) AS weekly ON (c.id = weekly.collection_id)\n        INNER JOIN (\n            SELECT\n                COUNT(collection_id) AS count,\n                collection_id\n            FROM collection_subscriptions\n            WHERE created >= DATE_SUB(CURDATE(), INTERVAL 31 DAY)\n            GROUP BY collection_id\n        ) AS monthly ON (c.id = monthly.collection_id)\n        SET c.weekly_subscribers = weekly.count,\n            c.monthly_subscribers = monthly.count\n    ')

@ cronjobs . register def collection_subscribers ( ) : log . debug ( 'Starting collection subscriber update...' ) if ( not waffle . switch_is_active ( 'local-statistics-processing' ) ) : return False cursor = connection . cursor ( ) cursor . execute ( '\n        UPDATE collections SET weekly_subscribers = 0, monthly_subscribers = 0\n    ' ) cursor . execute ( '\n        UPDATE collections AS c\n        INNER JOIN (\n            SELECT\n                COUNT(collection_id) AS count,\n                collection_id\n            FROM collection_subscriptions\n            WHERE created >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)\n            GROUP BY collection_id\n        ) AS weekly ON (c.id = weekly.collection_id)\n        INNER JOIN (\n            SELECT\n                COUNT(collection_id) AS count,\n                collection_id\n            FROM collection_subscriptions\n            WHERE created >= DATE_SUB(CURDATE(), INTERVAL 31 DAY)\n            GROUP BY collection_id\n        ) AS monthly ON (c.id = monthly.collection_id)\n        SET c.weekly_subscribers = weekly.count,\n            c.monthly_subscribers = monthly.count\n    ' )
collection weekly and monthly subscriber counts .