
ALTER TABLE was_sitecontent_user
	ADD COLUMN `indexed_article_count` int(11) unsigned NOT NULL DEFAULT 0 AFTER unpublished_article_count,
	ADD COLUMN `templates_count` int(11) unsigned NOT NULL DEFAULT 0 AFTER unpublished_article_count,
	ADD COLUMN `buckets_count` int(11) unsigned NOT NULL DEFAULT 0 AFTER unpublished_article_count;

UPDATE
	was_sitecontent_user u
	JOIN (
		SELECT
			user_id,
			count(*) AS indexed_article_count
		FROM
			was_sitecontent_article
		WHERE
			google_indexed_timestamp IS NOT NULL
		GROUP BY
			user_id) c ON u.user_id = c.user_id 
SET u.indexed_article_count = c.indexed_article_count;


UPDATE
	was_sitecontent_user u
	JOIN (
		SELECT
			user_id,
			count(*) AS templates_count
		FROM
			was_sitecontent_template
		GROUP BY
			user_id) c ON u.user_id = c.user_id 
SET u.templates_count = c.templates_count;


UPDATE
	was_sitecontent_user u
	JOIN (
		SELECT
			user_id,
			count(*) AS buckets_count
		FROM
			was_sitecontent_bucket
		GROUP BY
			user_id) c ON u.user_id = c.user_id 
SET u.buckets_count = c.buckets_count;