Commit d6556325 authored by Lukáš Lalinský's avatar Lukáš Lalinský

Fix stats

parent 5bc17690
......@@ -8,18 +8,18 @@ logger = logging.getLogger(__name__)
QUERIES = [
('account.all', 'SELECT count(*) FROM account'),
('account.musicbrainz', 'SELECT count(*) FROM account WHERE mbuser IS NOT NULL'),
('account.openid', 'SELECT count(DISTINCT account_id) FROM account_openid'),
('account.active', 'SELECT count(DISTINCT account_id) FROM source'),
('application.all', 'SELECT count(*) FROM application'),
('format.all', 'SELECT count(*) FROM format'),
('fingerprint.all', 'SELECT count(*) FROM fingerprint'),
('track_mbid.all', 'SELECT count(*) FROM track_mbid'),
('mbid.all', 'SELECT count(DISTINCT mbid) FROM track_mbid'),
('track.all', 'SELECT count(*) FROM track'),
('submission.all', 'SELECT sum(submission_count) FROM account'),
('submission.unhandled', 'SELECT count(*) FROM submission WHERE not handled'),
('app', 'account.all', 'SELECT count(*) FROM account'),
('app', 'account.musicbrainz', 'SELECT count(*) FROM account WHERE mbuser IS NOT NULL'),
('app', 'account.openid', 'SELECT count(DISTINCT account_id) FROM account_openid'),
('app', 'account.active', 'SELECT count(DISTINCT account_id) FROM source'),
('app', 'application.all', 'SELECT count(*) FROM application'),
('app', 'format.all', 'SELECT count(*) FROM format'),
('fingerprint', 'fingerprint.all', 'SELECT count(*) FROM fingerprint'),
('fingerprint', 'track_mbid.all', 'SELECT count(*) FROM track_mbid'),
('fingerprint', 'mbid.all', 'SELECT count(DISTINCT mbid) FROM track_mbid'),
('fingerprint', 'track.all', 'SELECT count(*) FROM track'),
('ingest', 'submission.all', 'SELECT sum(submission_count) FROM account'),
('ingest', 'submission.unhandled', 'SELECT count(*) FROM submission WHERE not handled'),
]
......@@ -61,21 +61,21 @@ def run_update_stats(script, opts, args):
logger.info('Not running update_stats in slave mode')
return
db = script.db_engines['app'].connect()
with db.begin():
with script.context() as ctx:
insert = tables.stats.insert()
for name, query in QUERIES:
for bind_key, name, query in QUERIES:
logger.info('Updating stats %s', name)
value = db.execute(query).scalar()
db.execute(insert.values({'name': name, 'value': value}))
value = ctx.db.connection(bind_key).execute(query).scalar()
ctx.db.get_app_db().execute(insert.values({'name': name, 'value': value}))
for i, value in get_track_count_stats(db, MBID_TRACK_QUERY):
for i, value in get_track_count_stats(ctx.db.get_fingerprint_db(), MBID_TRACK_QUERY):
name = 'mbid.%dtracks' % i
logger.info('Updating stats %s', name)
db.execute(insert.values({'name': name, 'value': value}))
ctx.db.get_app_db().execute(insert.values({'name': name, 'value': value}))
for i, value in get_track_count_stats(db, TRACK_MBID_QUERY):
for i, value in get_track_count_stats(ctx.db.get_fingerprint_db(), TRACK_MBID_QUERY):
name = 'track.%dmbids' % i
logger.info('Updating stats %s', name)
db.execute(insert.values({'name': name, 'value': value}))
ctx.db.get_app_db().execute(insert.values({'name': name, 'value': value}))
ctx.db.session.commit()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment