Wikia/app — pull request #4039 by macbre (2014-07-03 15:12:03+00:00)
Title: ImageServing: use content namespace only usage on images when calculating their popularity

https://wikia-inc.atlassian.net/browse/PLATFORM-285

Adding filtering by content namespace articles when counting how many times an image is used on a wiki.

The previous query:

```mysql
explain SELECT 'Potato.jpg' AS il_to FROM `imagelinks` WHERE il_to = 'Potato.jpg' LIMIT 11;
+----+-------------+------------+------+---------------+-------+---------+-------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+------+---------------+-------+---------+-------+------+--------------------------+
| 1 | SIMPLE | imagelinks | ref | il_to | il_to | 257 | const | 39 | Using where; Using index |
+----+-------------+------------+------+---------------+-------+---------+-------+------+--------------------------+
1 row in set (0.00 sec)
```

Query after the change:

```mysql
explain SELECT /* ImageServingDriverMainNS::getImagesPopularity::imagelinks */ 'Potato.jpg' AS il_to FROM `imagelinks` JOIN page on page.page_id = il_from WHERE il_to = 'Potato.jpg' AND page_namespace IN (0) LIMIT 11 ;
+----+-------------+------------+--------+--------------------+---------+---------+-----------------------------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+--------+--------------------+---------+---------+-----------------------------+------+--------------------------+
| 1 | SIMPLE | imagelinks | ref | il_from,il_to | il_to | 257 | const | 39 | Using where; Using index |
| 1 | SIMPLE | page | eq_ref | PRIMARY,name_title | PRIMARY | 4 | plpoznan.imagelinks.il_from | 1 | Using where |
+----+-------------+------------+--------+--------------------+---------+---------+-----------------------------+------+--------------------------+
2 rows in set (0.00 sec)
```

@Wikia/platform-team / @SQLReview