|
|
Registered User Currently Offline
|
Posts: 70
Join Date: Mar 2005
|
Recount User Statistics SP
Recount User Statistics kept timing out for me (I have over 2300 members). So I wrote a mySql stored procedure that does the job just fine:
Code:
DELIMITER $$
DROP PROCEDURE IF EXISTS `your_db`.`updateUserStats` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `updateUserStats`()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE pUserId, pTotal INT;
DECLARE cur1 CURSOR FOR select post_author_id, count(post_author_id) as total
from seo_board_posts group by post_author_id;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
OPEN cur1;
REPEAT
FETCH cur1 INTO pUserId, pTotal;
IF NOT done THEN
update seo_board_users SET user_numposts = pTotal where user_id = pUserId;
END IF;
UNTIL done END REPEAT;
CLOSE cur1;
END $$
DELIMITER ;
|