MyBB Threadcache
leefish Offline
Hamster
*****
Posts: 1,009
Joined: Apr 2010
Post: #1
MyBB Threadcache
I have been working on extending a plugin (favourite threads by Starpaul). I wanted to show on forumdisplay to a user if they had already favourited a thread.

I was able to do that, but at the cost of 2 queries per thread; the user and the tid. Not a good plan.

I looked at how MyBB get the doticons out as that seemed like a similar function, and indeed I was able to hack the core file to repurpose the doticons. But that feels like a wrong thing to do, as now I dont have any doticons.

So I added a function to the plugin, trying to get my data added to the threadcache so I could have less queries on my page.

This is my function:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$plugins->add_hook("forumdisplay_thread", "favorites_added");

//Starpaul code is all here

//My function

function favorites_added()
{
	global $db, $mybb, $templates, $thread, $theme, $lang, $favorites;
	$lang->load("favorites");
	
	// Check faves by the current user in any of these threads
	
	if($mybb->user['uid'] && !empty($threadcache))
	{
		$query = $db->simple_select("favorites", "tid,uid", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})");
		while($thread = $db->fetch_array($query))
		{
			if($threadcache[$thread['tid']])
			{
				$threadcache[$thread['tid']]['favorites'] = 1;
			}

		}

	}
	if($thread['favorites'] == 1)
		{
		$thread['fave'] = "HELLO";
		}
}


and unsurprisingly it does not work. Please can you help me get this right as I think this would be useful for other plugins I might make. Thank you.



[Image: leelink.gif]
MYBB1.6 & XThreads
(This post was last modified: 02-22-2015 11:29 PM by leefish.)
02-22-2015 11:54 AM
Visit this user's website Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
MyBB Threadcache - leefish - 02-22-2015 11:54 AM
RE: MyBB Threadcache - ZiNgA BuRgA - 02-23-2015, 04:44 PM
RE: MyBB Threadcache - leefish - 02-25-2015, 02:22 PM
RE: MyBB Threadcache - Sama34 - 02-27-2015, 04:08 PM
RE: MyBB Threadcache - leefish - 02-27-2015, 08:20 PM
RE: MyBB Threadcache - ZiNgA BuRgA - 02-27-2015, 08:37 PM
RE: MyBB Threadcache - Sama34 - 02-28-2015, 04:48 PM
RE: MyBB Threadcache - leefish - 03-01-2015, 02:20 PM
RE: MyBB Threadcache - ZiNgA BuRgA - 03-01-2015, 05:23 PM
RE: MyBB Threadcache - Sama34 - 03-02-2015, 06:52 AM

 Standard Tools
Forum Jump: