Hi folks
A website I am working with has grown fairly large and we’re starting to take a hit from my (admittedly) fairly novice SQL queries.
I have an hourly cron job which calculates the number of views which an article has received. I have over 10000 articles and for compatibility with my predecessor’s code, we have a 10 million row “views” table.
We’re trying to tweak this query:
UPDATE `articles` a
SET a.views = a.views + (
SELECT COUNT( apv.id ) FROM `article_pages` ap
LEFT JOIN `article_page_views` apv ON page_id = ap.id
WHERE ap.article_id = a.id AND apv.created > 1277878382
)
I would like it to only update articles for which there are actually new page views. I am doing this the wrong way round though, because it updates every article in the database (whether they have a new view or not) – just not sure how to fix it!
Thanks in advance for your assistance!