@celery.task(name='redash.tasks.cleanup_query_results', base=BaseTask)
def cleanup_query_results():
 logging.info('Running query results clean up (removing maximum of %d unused results, that are %d days old or more)', settings.QUERY_RESULTS_CLEANUP_COUNT, settings.QUERY_RESULTS_CLEANUP_MAX_AGE)
 unused_query_results = models.QueryResult.unused(settings.QUERY_RESULTS_CLEANUP_MAX_AGE).limit(settings.QUERY_RESULTS_CLEANUP_COUNT)
 total_unused_query_results = models.QueryResult.unused().count()
 deleted_count = models.Query.query.filter(models.Query.id.in_(unused_query_results.subquery())).delete(synchronize_session=False)
 models.db.session.commit()
 logger.info(('Deleted %d unused query results out of total of %d.' % (deleted_count, total_unused_query_results)))

@ celery . task ( name = 'redash.tasks.cleanup_query_results' , base = BaseTask ) def cleanup_query_results ( ) : logging . info ( 'Running query results clean up (removing maximum of %d unused results, that are %d days old or more)' , settings . QUERY_RESULTS_CLEANUP_COUNT , settings . QUERY_RESULTS_CLEANUP_MAX_AGE ) unused_query_results = models . QueryResult . unused ( settings . QUERY_RESULTS_CLEANUP_MAX_AGE ) . limit ( settings . QUERY_RESULTS_CLEANUP_COUNT ) total_unused_query_results = models . QueryResult . unused ( ) . count ( ) deleted_count = models . Query . query . filter ( models . Query . id . in_ ( unused_query_results . subquery ( ) ) ) . delete ( synchronize_session = False ) models . db . session . commit ( ) logger . info ( ( 'Deleted %d unused query results out of total of %d.' % ( deleted_count , total_unused_query_results ) ) )
job to cleanup unused query results -- such that no query links to them anymore .