Skip to content

Commit

Permalink
Merge article used and unique used query
Browse files Browse the repository at this point in the history
  • Loading branch information
maskara committed Nov 30, 2018
1 parent 916b18f commit 5d835f2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def featuredImages(username):
response[award] = 0
return response

def articlesUsingAndUniqueUsedImages(username):
with conn.cursor() as cur:
sql = 'select count(*) as articlesUsing, count(distinct gil_to) as uniqueUsed from globalimagelinks where gil_to in (select log_title from logging_userindex where log_type="upload" and log_user=(select user_id from user where user_name="%s"));' % username
cur.execute(sql)
data = cur.fetchall()
return data[0][0], data[0][1]

def articlesUsingImages(username):
with conn.cursor() as cur:
sql = 'select count(*) from globalimagelinks where gil_to in (select log_title from logging_userindex where log_type="upload" and log_user=(select user_id from user where user_name="%s"));' % username
Expand Down Expand Up @@ -107,10 +114,15 @@ def deletedUploads(username):
response['thanksReceived'] = thanksReceived(user)
if 'featuredImages' in fetch:
response['featuredImages'] = featuredImages(user)
if 'articlesUsingImages' in fetch:
response['articlesUsingImages'] = articlesUsingImages(user)
if 'uniqueUsedImages' in fetch:
response['uniqueUsedImages'] = uniqueUsedImages(user)
if 'articlesUsingImages' in fetch and 'uniqueUsedImages' in fetch:
resp = articlesUsingAndUniqueUsedImages(user)
response['articlesUsingImages'] = resp[0]
response['uniqueUsedImages'] = resp[1]
else:
if 'articlesUsingImages' in fetch:
response['articlesUsingImages'] = articlesUsingImages(user)
if 'uniqueUsedImages' in fetch:
response['uniqueUsedImages'] = uniqueUsedImages(user)
if 'imagesEditedBySomeoneElse' in fetch:
response['imagesEditedBySomeoneElse'] = imagesEditedBySomeoneElse(user)
if 'deletedUploads' in fetch:
Expand Down

0 comments on commit 5d835f2

Please sign in to comment.