[odrs-web] Fix app stats collection
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [odrs-web] Fix app stats collection
- Date: Mon, 1 Jul 2019 16:13:53 +0000 (UTC)
commit 9ba1759219c854a201a27bae1be604f4d81e2097
Author: Richard Hughes <richard hughsie com>
Date: Mon Jul 1 14:50:48 2019 +0100
Fix app stats collection
app_data/odrs/views_api.py | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/app_data/odrs/views_api.py b/app_data/odrs/views_api.py
index 8ca5311..1447d96 100644
--- a/app_data/odrs/views_api.py
+++ b/app_data/odrs/views_api.py
@@ -12,6 +12,7 @@ import math
import datetime
from sqlalchemy.dialects.mysql import insert
+from sqlalchemy.exc import IntegrityError
from flask import request, Response
@@ -178,12 +179,14 @@ def api_fetch():
datestr = _get_datestr_from_dt(datetime.date.today())
stmt = insert(Analytic).values(datestr=datestr, app_id=item['app_id'])
if db.session.bind.dialect.name != 'sqlite': # pylint: disable=no-member
- stmt_ondupe = stmt.on_duplicate_key_update(datestr=stmt.inserted.datestr,
- app_id=stmt.inserted.app_id,
- fetch_cnt=stmt.inserted.fetch_cnt + 1)
+ stmt_ondupe = stmt.on_duplicate_key_update(fetch_cnt=Analytic.fetch_cnt + 1)
else:
stmt_ondupe = stmt
- db.session.execute(stmt_ondupe) # pylint: disable=no-member
+ try:
+ db.session.execute(stmt_ondupe) # pylint: disable=no-member
+ db.session.commit()
+ except IntegrityError as e:
+ print('ignoring: {}'.format(str(e)))
# also add any compat IDs
app_ids = [item['app_id']]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]