Skip to content

Commit

Permalink
retrieve first uploader if file has multiple versions (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
slaporte committed Oct 8, 2019
1 parent 924c6a0 commit 69cbb61
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions montage/labs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
'img_name',
'img_major_mime',
'img_minor_mime',
'actor_user AS img_user',
'actor_name AS img_user_text',
'img_timestamp']
'IFNULL(oi.actor_user, ci.actor_user) AS img_user',
'IFNULL(oi.actor_name, ci.actor_name) AS img_user_text',
'img_timestamp',
'oi_timestamp']


class MissingMySQLClient(RuntimeError):
Expand All @@ -41,13 +42,22 @@ def fetchall_from_commonswiki(query, params):
def get_files(category_name):
query = '''
SELECT {cols}
FROM commonswiki_p.image
LEFT JOIN actor ON img_actor=actor.actor_id
FROM commonswiki_p.image AS i
LEFT JOIN actor AS ci ON img_actor=ci.actor_id
LEFT JOIN (SELECT oi_name,
oi_actor,
actor_user,
actor_name,
oi_timestamp
FROM oldimage
LEFT JOIN actor ON oi_actor=actor.actor_id) AS oi ON img_name=oi.oi_name
JOIN page ON page_namespace = 6
AND page_title = img_name
JOIN categorylinks ON cl_from = page_id
AND cl_type = 'file'
AND cl_to = %s;
AND cl_to = %s
GROUP BY img_name
ORDER BY oi_timestamp ASC;
'''.format(cols=', '.join(IMAGE_COLS))
params = (category_name.replace(' ', '_'),)

Expand All @@ -59,9 +69,18 @@ def get_files(category_name):
def get_file_info(filename):
query = '''
SELECT {cols}
FROM commonswiki_p.image
LEFT JOIN actor ON img_actor=actor.actor_id
WHERE img_name = %s;
FROM commonswiki_p.image AS i
LEFT JOIN actor AS ci ON img_actor=ci.actor_id
LEFT JOIN (SELECT oi_name,
oi_actor,
actor_user,
actor_name,
oi_timestamp
FROM oldimage
LEFT JOIN actor ON oi_actor=actor.actor_id) AS oi ON img_name=oi.oi_name
WHERE img_name = %s
GROUP BY img_name
ORDER BY oi_timestamp ASC;
'''.format(cols=', '.join(IMAGE_COLS))
params = (filename.replace(' ', '_'),)
results = fetchall_from_commonswiki(query, params)
Expand Down

0 comments on commit 69cbb61

Please sign in to comment.