The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
vBcron batching?
Well i'm just looking into it. I need to run about 10k queries every night around midnight. The queries are ran in threes. Two selects and one update.
Obviously it would not be sensible to run that many queries in one go. So would it be possible to do it in batches using vBcron? |
#2
|
||||
|
||||
Jeez! Are you sure the there isn't smth. wrong with your database design?
|
#3
|
||||
|
||||
Hehe probably Basically i'm upgrading my battle system to work vB3. I have my table structure like so:
Code:
CREATE TABLE `battle_records` ( `battleid` smallint(5) unsigned NOT NULL auto_increment, `userid1` smallint(5) unsigned NOT NULL default '0', `userid2` smallint(5) unsigned NOT NULL default '0', `votesforuserid1` smallint(5) unsigned NOT NULL default '0', `votesforuserid2` smallint(5) unsigned NOT NULL default '0', `threadid` text NOT NULL, `battletype` varchar(50) NOT NULL default '', `timeadded` int(14) default NULL, `winner` smallint(5) unsigned NOT NULL default '0', PRIMARY KEY (`battleid`) ) TYPE=MyISAM AUTO_INCREMENT=1888 ; |
#4
|
|||
|
|||
if you have shell access I'd recommend doing something this big via unix cron.
if you don't have shell access then batching is possible but would be tough. You'd have to write somewhere (either in the db or a file) saying how far a previous batch got so that you're not redoing queries. This opens up race conditions where you'd have to obtain a semaphore before starting... (A semaphore is a lock, if one process already has the lock then the next one who wants the lock will wait until the one holding the lock is finished.) Something similar to this at the top of the batch file PHP Code:
|
#5
|
||||
|
||||
Interesting, I've never worked with a real-cron system on UNIX so I'll talk to my server admin when he gets back off holiday and see what we can do
|
#6
|
||||
|
||||
Hmm, I am not sure about your table structure and what you actuaklly want to do, but assuming that winner is the userid which won the battle and that your user table has fiels battles, wins and losses for the # of battles, wins and losses of each user, the following queries might work:
[sql] CREATE TEMPORARY TABLE battle_results_temp (userid INT( 10 ) NOT NULL , battles INT( 10 ) NOT NULL , wins INT( 10 ) NOT NULL); CREATE TEMPORARY TABLE battle_results_temp2 (userid INT( 10 ) NOT NULL , battles INT( 10 ) NOT NULL , wins INT( 10 ) NOT NULL, losses INT (10) NOT NULL); INSERT INTO battle_results_temp SELECT userid1 AS userid, COUNT(userid1) AS battles, SUM(IF(userid1=winner, 1, 0)) AS wins FROM battle_records GROUP BY userid1; INSERT INTO battle_results_temp SELECT userid2 AS userid, COUNT(userid2) AS battles, SUM(IF(userid2=winner, 1, 0)) AS wins FROM battle_records GROUP BY userid2; INSERT INTO battle_results_temp2 SELECT userid, SUM(battles) AS battles, SUM(wins) AS wins, SUM(battles) - SUM(wins) AS losses FROM battle_results_temp GROUP BY userid; UPDATE battle_results_temp2, user SET user.battles=battle_results_temp2.battles, user.wins=battle_results_temp2.wins, user.losses=battle_results_temp2.losses WHERE battle_results_temp2.userid=user.userid; [/sql] |
#7
|
||||
|
||||
another way would be to use the CASE function to assign different values to different users, you can save a lot of queries that way
|
#8
|
||||
|
||||
My table is exactly as it is above. Right now I have this query which will give me the wins/losses for a user (thanks to a guy at sitepoint):
Code:
select sum( case when $id = userid1 and votesforuserid1 > votesforuserid2 or $id = userid2 and votesforuserid1 < votesforuserid2 then 1 else 0 end ) as wins , sum( case when $id = userid1 and votesforuserid1 > votesforuserid2 or $id = userid2 and votesforuserid1 < votesforuserid2 then 0 else 1 end ) as losses from battle_records where $id in ( userid1 , userid2 ) The thing that i'm stuck with now is the easiest way to run that for all my users every night. Obviously running that 10,000 times is not very efficient. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|