Thread Rating:
  • 15 Vote(s) - 4.13 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[For 1.8] OUGC Awards
#81
This user has been denied support. This user has been denied support.
I shall try now implementing your function, however, don't you think you're unnecessary selecting or querying data from pm db? The below is my function, and I don't query pm table, still it outputs correctly, all the awards in the PM:

function ougc_awards_postbit(&$post)
{
	global $mybb;

	$post['ougc_awards'] = '';
	$max_postbit = intval($mybb->settings['ougc_awards_postbit']);
	if($mybb->settings['ougc_awards_power'] == 1 && ($max_postbit > 0 || $max_postbit == -1))
	{
		global $cache, $templates, $db;
		
		//$cache_awards = $cache->read('ougc_awards');
		
		$query = $db->query("
			SELECT u.*, a.* 
			FROM ".TABLE_PREFIX."ougc_awards a
			LEFT JOIN ".TABLE_PREFIX."ougc_awards_users u ON (u.aid=a.aid)
			WHERE u.uid='".intval($post['uid'])."'
			ORDER BY u.date ASC
		");
		
	while($award = $db->fetch_array($query))
			{
				//if(in_array($post['uid'], $award['users']))
				//{
				    //global $custom_ougc_awards_postbit;
					
					$award['aid'] = intval($award['aid']);
					$award['name'] = ougc_awards_get_award_info('name', $award['aid'], $award['name']);
					$award['image'] = ougc_awards_get_icon($award['image']);
					if($max_postbit == -1 || $count < $max_postbit)
					{
						$count++;
						$br = '';
						if($count == 1)
						{
							$br = '<br />'; // We insert a break if it is the first award.
						}
						$post['ougc_awards'] .= "<img src=\"".$award['image']."\" title=\"".$award['name']."\" alt=\"".$award['name']."\" />";
					}
					//return $post;
				//}
			}
		}
	}

However, this runs numerous queries (one query per uid, so max of 10 queries per page if depending upon the # of replies set to view per each thread page).

Any cache edits that I could make with my current code?
Reply
#82
My function is written in such a way that it uses the minimum queries as possible and it should work for you, just apply your edits over my code.
Reply
#83
This user has been denied support. This user has been denied support.
I used your code directly just to test, but it doesn't seem to output any awards, at the most, only outputted one award on some posts.

And yeah, I did manually added <!--OUGC_AWARDS--> to postbit_author_user template.
Reply
#84
It seems to work for me. What if I send you a copy of the new version via PM? Will you be willing to test it?
Reply
#85
This user has been denied support. This user has been denied support.
Hmm, I have made numerous edits, not sure if I could test the plugin as is, but I may test for the postbit function, or eventually I will have to use what I currently have and try caching part some other day.

If you're willing to take a look at my current plugin code and suggest a fix for it or test it, I'd be glad to do so.

I've been porting for so many days and guess I'm very tired now, but I gotta do what I'm supposed to.

Let me know.
Reply
#86
This should work:
function ougc_awards_postbit(&$post)
{
    global $mybb, $pids;

    $post['ougc_awards'] = '';
    $max_postbit = intval($mybb->settings['ougc_awards_postbit']);
    if($mybb->settings['ougc_awards_power'] == 1 && ($max_postbit > 0 || $max_postbit == -1) &&  $pids)
    {
        global $db;

		static $ougc_awards_cache = null;
		if(!isset($ougc_awards_cache))
		{
			global $db, $pids;

			$query = $db->query("
				SELECT a.aid, a.name, a.image, p.uid
				FROM ".TABLE_PREFIX."ougc_awards a
				JOIN ".TABLE_PREFIX."ougc_awards_users ag ON (ag.aid=a.aid)
				JOIN ".TABLE_PREFIX."posts p ON (p.uid=ag.uid)
				WHERE p.{$pids} AND a.visible='1' AND a.type!='1'
				ORDER BY ag.date desc
			");
		
			while($data = $db->fetch_array($query))
			{
				$ougc_awards_cache[$data['uid']][$data['aid']] = $data;
			}
		}

		if(!(isset($ougc_awards_cache[$post['uid']]) && is_array($ougc_awards_cache[$post['uid']])))
		{
			return;
		}

		foreach($ougc_awards_cache[$post['uid']] as $award)
            {
                //if(in_array($post['uid'], $award['users']))
                //{
                    //global $custom_ougc_awards_postbit;
                    
                    $award['aid'] = intval($award['aid']);
                    $award['name'] = ougc_awards_get_award_info('name', $award['aid'], $award['name']);
                    $award['image'] = ougc_awards_get_icon($award['image']);
                    if($max_postbit == -1 || $count < $max_postbit)
                    {
                        $count++;
                        $br = '';
                        if($count == 1)
                        {
                            $br = '<br />'; // We insert a break if it is the first award.
                        }
                        $post['ougc_awards'] .= "<img src=\"".$award['image']."\" title=\"".$award['name']."\" alt=\"".$award['name']."\" />";
                    }
                    //return $post;
                //}
            }
        }
    } 
Reply
#87
This user has been denied support. This user has been denied support.
That works great and up to my expectations. I'm now saving around 8-9 queries on showthread, nice IMHO.

Well, thanks for your time and especially the plugin, appreciated. I will suggest if I have anything in mind.

edit: Sorry I had to delete this post, in order to bring a notice to you.

I have a suggestion for your update, however, I made changes to suit my needs. When you view awards of a specific user, only 3 rows (namely award's image, description & date) shows up, no name of award.

You may want to fix it in your next update, I've edited it anyways.

edit #2: The function you gave doesn't work for PM, I'm building a new function for PM, if you find any solution to that, let me know and I shall update it.

Btw, I think it doesn't work because you are querying posts table at the same time and comparing post uid with awards, so in PM's, there is no posts and hence, they're not displayed.

edit #3: Another bug (small problem) I currently have is as it caches initially, when a user that has award posts through quick reply, the awards doesn't show up and one has to reload the page. Any solution?

I guess the quick reply uses Ajax? Hence I came out to know $mybb->input['ajax'] function and used if condition and then ran that old query if so is the condition, but it doesn't work, however.
Reply
#88
Quote:Btw, I think it doesn't work because you are querying posts table at the same time and comparing post uid with awards, so in PM's, there is no posts and hence, they're not displayed.

That is the reason I posted this code, I use the same function for all postbit areas, and I adapted it to work on them all.

Quote:edit #3: Another bug (small problem) I currently have is as it caches initially, when a user that has award posts through quick reply, the awards doesn't show up and one has to reload the page. Any solution?

Quick reply is tricky (yes, it uses AJAX), I will need to find a solution, thanks for reporting.
Reply
#89
This user has been denied support. This user has been denied support.
I'm currently running a query in PMs as the postbit function isn't getting to work, if you do find solution for it (the older function doesn't work for me), do let me know. It's only one query, but hey, if I could save it, that'd be great.

I'll be looking more into AJAX/quick reply part today if I find time.
Reply
#90
My "fix" also runs one query at postbit, there is no real way to reduce that, not in this plugin at least. I have not checked the quick reply stuff yet. Checking the code I don't see the reason for it to fail, it uses the post functions which is where I hook. But again, I have no time for this just now, I have been updating the code all this week and now I need to jump to other projects.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)