Skip to content

Commit db2c64c

Browse files
authored
Merge pull request #48 from wikimedia/templatelinks
reports: update queries following templatelinks normalization
2 parents b3a1171 + 478c4d0 commit db2c64c

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

reports.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,11 @@ def deleted_prods(self):
363363
self.publish_report("deletedprods-page-title", text)
364364

365365
def most_used_templates(self):
366-
query = """SELECT tl_title, COUNT(*)
366+
query = """SELECT lt_title, COUNT(*)
367367
FROM templatelinks
368-
WHERE tl_namespace = 10
369-
GROUP BY tl_title
368+
JOIN linktarget ON tl_target_id = lt_id
369+
WHERE lt_namespace = 10
370+
GROUP BY lt_title
370371
ORDER BY COUNT(*) DESC
371372
LIMIT 3000"""
372373
content = []
@@ -381,14 +382,12 @@ def most_used_templates(self):
381382
def unused_templates(self):
382383
query = """SELECT page_title
383384
FROM page
384-
LEFT JOIN categorylinks
385-
ON page_id = cl_from
386-
AND cl_to = 'Wikipedia_substituted_templates'
387-
LEFT JOIN redirect
388-
ON rd_from = page_id
389-
LEFT JOIN templatelinks
390-
ON page_namespace = tl_namespace
391-
AND page_title = tl_title
385+
LEFT JOIN categorylinks ON page_id = cl_from
386+
AND cl_to = 'Wikipedia_substituted_templates'
387+
LEFT JOIN redirect ON rd_from = page_id
388+
LEFT JOIN linktarget ON page_namespace = lt_namespace
389+
AND page_title = lt_title
390+
LEFT JOIN templatelinks ON tl_target_id = lt_id
392391
WHERE page_namespace = 10
393392
AND rd_from IS NULL
394393
AND tl_from IS NULL
@@ -417,8 +416,10 @@ def orphaned_talk(self):
417416
AND NOT EXISTS (
418417
SELECT 1
419418
FROM templatelinks
419+
JOIN linktarget ON tl_target_id = lt_id
420420
WHERE talkpage.page_id=tl_from
421-
AND tl_title='G8-exempt'
421+
AND lt_title='G8-exempt'
422+
AND lt_namespace = 10
422423
)
423424
LIMIT 1000"""
424425
content = []

0 commit comments

Comments
 (0)