Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.0 > vBulletin 3.0 Full Releases
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Improve performance on thread view updating Details »»
Improve performance on thread view updating
Version: 1.00, by dwh dwh is offline
Developer Last Online: Nov 2023 Show Printable Version Email this Page

Version: 3.0.7 Rating:
Released: 03-16-2005 Last Update: Never Installs: 16
 
No support by the author.

Per Doc Erwin:
http://www.vbulletin.com/forum/showp...8&postcount=18
I'm releasing this here.

I have a suggestion to improve performance although it is for mysql 4.04 and up (I assume at some point a future version of vb will require it).

Requirements: MySQL 4.04

If you have a large forum, run mysql 4.04 and up and want to try this, please report back on your results.

The way updating threads views works right now, (even though putting it in cron improved things,) you are still going through many queries to the thread table, potentially locking it up while updating views.The current code from threadviews.php is:

PHP Code:
PHP Code:
$threads $DB_site->query("SELECT threadid , COUNT(*) AS views FROM " TABLE_PREFIX "threadviews GROUP BY threadid");
 
while (
$thread $DB_site->fetch_array($threads))
{
$DB_site->query(
"UPDATE " TABLE_PREFIX "thread
SET views = views + " 
intval($thread['views']) . "
WHERE threadid = " 
intval($thread['threadid'])
);



With 4.04 you can do a multitable update.
FIRST, create the table ONCE ONLY
PHP Code:
PHP Code:
CREATE TABLE `threadviewsaggregate` (
`
threadidint(10NOT NULL default '0',
`
viewsint(10NOT NULL default '0',
PRIMARY KEY (`threadid`)
TYPE=MyISAM
and in the threadviews.php code change it to

PHP Code:
PHP Code:
$DB_site->query("INSERT INTO ".TABLE_PREFIX ."threadviewsaggregate SELECT threadid , COUNT(*) AS views FROM " TABLE_PREFIX "threadviews GROUP BY threadid");
$DB_site->query("DELETE FROM " TABLE_PREFIX "threadviews"); 
 
$DB_site->query(
"UPDATE " TABLE_PREFIX "thread,"TABLE_PREFIX ."threadviewsaggregate 
SET "
TABLE_PREFIX ."thread.views = "TABLE_PREFIX ."thread.views + ".TABLE_PREFIX."threadviewsaggregate.views
WHERE "
TABLE_PREFIX ."thread.threadid = "TABLE_PREFIX ."threadviewsaggregate.threadid"); 
 
$DB_site->query("DELETE FROM "TABLE_PREFIX ."threadviewsaggregate"); 

That will reduce the number of queries by however many threads get updated in the cron interval. Additionally, you might be able to skip creating the extra table using subqueries. I haven't gotten around to writing that code yet. If someone wants to add that,mention it in this thread and I'll update the code.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #22  
Old 04-19-2005, 03:50 PM
dwh's Avatar
dwh dwh is offline
 
Join Date: Feb 2002
Posts: 278
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

For some reason, lately when I post here, the spaces get pulled out and words are stuck together. I have no idea why.
Reply With Quote
  #23  
Old 04-20-2005, 12:23 AM
WebMasterAJ WebMasterAJ is offline
 
Join Date: Oct 2001
Posts: 104
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I just installed this... so far so good
Reply With Quote
  #24  
Old 04-23-2005, 07:25 AM
tp214 tp214 is offline
 
Join Date: Sep 2004
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

did the edits keep getting this

Code:
Database error in vBulletin 3.0.7:

Invalid SQL: INSERTINTOthreadviewsaggregate SELECT threadid , COUNT(*)ASviewsFROM threadviews GROUP BY threadid
mysql error: You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERTINTOthreadviewsaggregate SELECT threadid , COUNT(*)ASview

mysql error number: 1064

Date: Saturday 23rd of April 2005 03:25:03 AM
Script: http://www.v3gamer.com/forums/admincp/cronadmin.php?do=runcron&cronid=2
Referer: http://www.v3gamer.com/forums/admincp/index.php?
Username: admin
IP Address: xx.xx.xx.xxx
Reply With Quote
  #25  
Old 04-23-2005, 07:27 AM
tp214 tp214 is offline
 
Join Date: Sep 2004
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

nevermind!

this is the correct code...

Code:
error_reporting(E_ALL & ~E_NOTICE); 

if (!is_object($DB_site)) 
{ 
        exit; 
} 

$DB_site->query("INSERT INTO ". TABLE_PREFIX ."threadviewsaggregate SELECT threadid , COUNT(*) AS views FROM " . TABLE_PREFIX . "threadviews GROUP BY threadid"); 
$DB_site->query("DELETE FROM " . TABLE_PREFIX . "threadviews"); 

$DB_site->query( 
        "UPDATE " . TABLE_PREFIX . "thread,". TABLE_PREFIX ."threadviewsaggregate 
        SET ". TABLE_PREFIX ."thread.views = ". TABLE_PREFIX ."thread.views + ".TABLE_PREFIX."threadviewsaggregate.views 
        WHERE ". TABLE_PREFIX ."thread.threadid = ". TABLE_PREFIX ."threadviewsaggregate.threadid"); 
$DB_site->query("DELETE FROM ". TABLE_PREFIX ."threadviewsaggregate"); 

log_cron_action('Thread Views Updated', $nextitem);
Reply With Quote
  #26  
Old 04-28-2005, 12:43 PM
LambHyjoo LambHyjoo is offline
 
Join Date: Apr 2005
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi, and first of all thank you for this release.

I was just wondering if it is normal that the "threadviewsaggregate" table remains empty ?
Reply With Quote
  #27  
Old 05-01-2005, 01:52 PM
Link14716's Avatar
Link14716 Link14716 is offline
 
Join Date: Jun 2002
Location: Georgia, USA
Posts: 2,519
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by LambHyjoo
Hi, and first of all thank you for this release.

I was just wondering if it is normal that the "threadviewsaggregate" table remains empty ?
Yes, because it is only used when threadviews is being updated.
Reply With Quote
  #28  
Old 05-02-2005, 07:05 AM
LambHyjoo LambHyjoo is offline
 
Join Date: Apr 2005
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, thanks for the answear
Reply With Quote
  #29  
Old 05-03-2005, 01:36 AM
RichieBoy67's Avatar
RichieBoy67 RichieBoy67 is offline
 
Join Date: Apr 2004
Location: CT - Down in a hole..
Posts: 3,057
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How about a downloadable text file with edits @ instructions???
Reply With Quote
  #30  
Old 05-07-2005, 08:25 PM
djwins djwins is offline
 
Join Date: Jan 2005
Posts: 167
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So, is the best code in the first post, or am I supposed to use one of the other users contributions?

Also, I am running mySQL 4.0.24. Will this work with my version?

Thanks!
Reply With Quote
  #31  
Old 05-08-2005, 05:15 AM
dsboyce8624 dsboyce8624 is offline
 
Join Date: May 2005
Location: New Jersey
Posts: 413
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay, I'd like to try this, but AdminCP says I don't have permission to execute queries. I tried pasting the create table stuff into the MySQL command box, but it said I needed to specify a datavase. I don't know the sytax so I couldn't.

A little help here please.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:36 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04503 seconds
  • Memory Usage 2,320KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_code
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete