[odrs-web/oscp] Restore the Analytic duplicate handling
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [odrs-web/oscp] Restore the Analytic duplicate handling
- Date: Mon, 1 Jul 2019 15:43:31 +0000 (UTC)
commit c7c0bac0fa3dd5b35887dcd5b79c519b0ac96b9f
Author: Richard Hughes <richard hughsie com>
Date: Mon Jul 1 16:42:36 2019 +0100
Restore the Analytic duplicate handling
app_data/odrs/views_api.py | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/app_data/odrs/views_api.py b/app_data/odrs/views_api.py
index 325c511..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
@@ -175,15 +176,17 @@ def api_fetch():
return json_error('the user_hash is invalid')
# increments the fetch count on one specific application
-# 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)
-# else:
-# stmt_ondupe = stmt
-# db.session.execute(stmt_ondupe) # pylint: disable=no-member
+ 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(fetch_cnt=Analytic.fetch_cnt + 1)
+ else:
+ stmt_ondupe = stmt
+ 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]