To fix #2 requires editing of 2 files, but caches all warning notes in 1 query instead of 1 query per post.
First, edit showthread.php
Find:
Code:
$getpostids = $DB_site->query("
SELECT postid NOT ISNULL(deletionlog.primaryid) AS isdeleted
FROM " . TABLE_PREFIX . "post AS post
LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog ON(post.postid = deletionlog.primaryid AND type = 'post')
WHERE threadid = $threadid AND visible = 1
ORDER BY postid $postorder
");
Replace with:
Code:
$getpostids = $DB_site->query("
SELECT postid, post.userid, NOT ISNULL(deletionlog.primaryid) AS isdeleted
FROM " . TABLE_PREFIX . "post AS post
LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog ON(post.postid = deletionlog.primaryid AND type = 'post')
WHERE threadid = $threadid AND visible = 1
ORDER BY postid $postorder
");
// Start Cached Warning Notes
global $warn_notes;
$warn_query = $DB_site->query("SELECT w.*, u.username as warner from " . TABLE_PREFIX. "warn_notes w LEFT JOIN " . TABLE_PREFIX . "user u on (u.userid=w.warned_by) WHERE warned_user IN (0". $userids. ") ORDER BY warned_time DESC");
while ($warn_note = $DB_site->fetch_array($warn_query))
{
$warn_notes[$warn_note[warned_user]] = $warn_note;
}
$DB_site->free_result($warn_query);
// End Cached Warning Notes
Save the file, and upload.
Next, edit includes/functions_showthread.php
Find:
Code:
if ($post['warn_notes']==1 and $showviewwarnlink==1);
{
$get_notes=$DB_site->query("select w.*, u.username as warner from ".TABLE_PREFIX."warn_notes w
LEFT JOIN ".TABLE_PREFIX."user u on(u.userid=w.warned_by)
where warned_user='{$post['userid']}' order by warned_time desc");
Replace with:
Code:
if ($post['warn_notes']==1 and $showviewwarnlink==1);
{
global $warn_notes;
The new release contains the code I suggested above. That should prevent simple users from seeing the notes. If that does not work for you, I do not know what to suggest, since I haven't checked your code yet.
I have one question about the way you modified the code for reducing the number of queries for the notes. How do you handle a post-specific note? I went through your replacements, but I am not sure I noticed how a post-specific note is handled. Admitedly, I haven't done the changes in the files, but from looking in your code, I didn't see that.
Post specific notes are handled by your original code - all I'm doing is, instead of doing a query per note, just cache everything first in an array with 1 query, and then do a foreach through the loop to get post specific notes. It's all still 1 query for an entire thread as opposed to 1 per post.
I did your changes, as suggested, and for some reason, post-specific notes do not appear.
I added a Private, non-post-specific note and it appeared OK.
Then I added a Private, post-specific one too, and only the first appears.
I am sure it is something trivial, and your idea to reduce the queries is a great one, but I do not have the time to look further into it. If you can solve the problem, let me know.