MyBB Community Forums

Full Version: Delayed thread views - nonsense
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Last time, I was interested in this option and I decided to check it.
In result, I think that is not have any sense.
I know, what was the purpose of this function, but implementation does not change anything.

As we can read:
http://www.mybb.com/features/performance

Quote:MyBB keeps track of whenever a user views a thread to provide the number of views it's received. For larger forums, constantly updating this in the threads table meant tables were locked by the database server and posting time & modification would be affected.

It's now possible to have the number of views a thread receives updated in batches by the automated task scheduling system. The number of views a thread receives can now optionally be updated every X minutes instead of instantly.

Everything fine, nice idea, and code from showthread:

	if($mybb->settings['delayedthreadviews'] == 1)
	{
		$db->shutdown_query("INSERT INTO ".TABLE_PREFIX."threadviews (tid) VALUES('{$tid}')");
	}
	else
	{
		$db->shutdown_query("UPDATE ".TABLE_PREFIX."threads SET views=views+1 WHERE tid='{$tid}'");
	}

Everthing is ok, so look at threadviews table schema (I use schema from mysql beacuse it's the most popular):

$tables[] = "CREATE TABLE mybb_threadviews (
	tid int unsigned NOT NULL default '0',
	KEY (tid)
) ENGINE=MyISAM;";

Here is nonsense.
MyISAM.

If we make UPDATE or INSERT to MyISAM table, table is locked.
So... can anyone explain me the difference between lock on UPDATE and lock on INSERT + additional work to do (second table, task etc.)?

Yes, it's good idea, but only when we use InnoDB.
It's good choice to use InnoDB for threadviews and MyISAM for threads beacuse of FULLTEXT index, it's clear.
(2013-01-03, 12:46 PM)lukasamd Wrote: [ -> ]So... can anyone explain me the difference between lock on UPDATE and lock on INSERT + additional work to do (second table, task etc.)?
On large forums mybb_threadviews is probably much smaller than mybb_threads and the query probably faster. Moreover mybb_threadviews is only used when you view a thread (and after the output is generated) whereas mybb_threads is used on a lot of other pages.