Thread: Moderators Functions - Force Users to Read a Thread
View Single Post
  #352  
Old 09-11-2009, 12:16 AM
s810car s810car is offline
 
Join Date: Mar 2008
Posts: 50
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just some friendly developer advice, you can chose to look at this and implement or not, but I would suggest either following what I did or the developer may have a better solution I didn't think of. I ran an EXPLAIN query on this SELECT query since it showed up in my slow queries log
PHP Code:
$force_thread $db->query_first("
            SELECT *
            FROM " 
TABLE_PREFIX "thread AS thread
            LEFT JOIN " 
TABLE_PREFIX "force_read_users AS force_read_users ON (thread.threadid = force_read_users.force_read_threadid AND force_read_users.force_read_userid = '".$vbulletin->userinfo['userid']."')
            WHERE thread.force_read = '1' AND (thread.force_read_expire_date = '0' OR thread.force_read_expire_date > '"
.TIMENOW."') AND ("implode(' OR '$where_usergroups) .") AND ("implode(' OR '$where_forums) .") AND force_read_users.force_read_userid IS NULL
            ORDER BY force_read_order ASC
        "
); 
Obviously I entered in some values into it to make the variables work in phpMyAdmin. Here's what i found with my relatively small forum:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE thread ALL NULL NULL NULL NULL 11877 Using where; Using filesort
1 SIMPLE force_read_users eq_ref PRIMARY PRIMARY 8 const,temp1.thread.threadid 1 Using where; Using index; Not exists

I added a index to the 'thread.force_read' row (since its boolean and a super small length) and heres the improvement

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE thread ref force_read force_read 1 const 18 Using where; Using filesort
1 SIMPLE force_read_users eq_ref PRIMARY PRIMARY 8 const,temp1.thread.threadid 1 Using where; Using index; Not exists

Should give you a MUCH more efficient query, I only have a few threads in my forum that we use the force read for (like for new rules), so I would think a site that uses this all the time with a lot more threads would see a substantial improvement

PS apologize for the terrible formatting of the exlpain query, never could line up columns easy on vbulletin
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01228 seconds
  • Memory Usage 1,782KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • 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
  • showpost_complete