Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Sep 2001
Posts: 5
Lurker
Lurker
Offline
Joined: Sep 2001
Posts: 5
Quick note, since I'm in a hurry: there's a way to reduce the query count for the ubbthreads.php by making the following changes. Right now UBBT checks if there are new posts on this board, if yes, it checks how many new threads there are. Two queries. In this version, the first query grabs both numbers, and that's it.

Depending on the number of boards you can save 20% - 40% of the original number of queries. On my BBS, there are ~150 boards (admin view, there are many private boards), and I save roughly 90 queries.

Anyways, instructions: Find (around line 312)...


// --------------------------------------------------------------
// Let's see how many new posts there are. We have to do some
// tricky AND/OR operations because we don't want sticky posts to
// be counted as new if they are not
$query = "
SELECT COUNT(*)
FROM w3t_Posts
WHERE ( (B_Posted > $checker AND B_Posted <> 4294967295)
OR (B_Posted = 4294967295 AND B_Sticky > $checker) )
$Viewable
AND B_Board = '$Board_q'
";
$newp = $dbh -> do_query($query);
list($newposts) = $dbh -> fetch_array($newp);
$dbh -> finish_sth($newposts);
if ($newposts) {
$shownew = "<br><font class="new">($newposts {$ubbt_lang['NEW_TEXT']})</font>";
}

// -----------------------------------------------------------
// If we have new posts let's see how many new threads we have
if ($newposts) {
$query = "
SELECT COUNT(*)
FROM w3t_Posts
WHERE ( (B_Posted > $checker AND B_Posted <> 4294967295)
OR (B_Posted = 4294967295 AND B_Sticky > $checker) )
$Viewable
AND B_Board = '$Board_q'
AND B_Topic = 1
";
$newt = $dbh -> do_query($query);
list($newthreads) = $dbh -> fetch_array($newt);
$dbh -> finish_sth($newt);
if ($newthreads) {
$shownewt = "<br><font class="new">($newthreads {$ubbt_lang['NEW_TEXT']})</font>";
}
}


... and replace with ...


// --------------------------------------------------------------
// Let's see how many new posts there are. We have to do some
// tricky AND/OR operations because we don't want sticky posts to
// be counted as new if they are not
// Routine changed to reduce query count
$query = "
SELECT COUNT(*), SUM(B_Topic)
FROM w3t_Posts
WHERE ( (B_Posted > $checker AND B_Posted <> 4294967295)
OR (B_Posted = 4294967295 AND B_Sticky > $checker) )
$Viewable
AND B_Board = '$Board_q'
";
$newp = $dbh -> do_query($query);
$newposts = $dbh -> fetch_array($newp);
$dbh -> finish_sth($newposts);
$newthreads = $newposts[1];
$newposts = $newposts[0];
if ($newposts) {
$shownew = "<br><font class="new">($newposts {$ubbt_lang['NEW_TEXT']})</font>";
}

// -----------------------------------------------------------
// If we have new posts let's see how many new threads we have
// Routine changed to reduce query count
if ($newthreads) {
$shownewt = "<br><font class="new">($newthreads {$ubbt_lang['NEW_TEXT']})</font>";
}


Voila, that's it. Don't forget to make a backup first. If you want to further reduce the load, replace the COUNT(*) with COUNT(B_IP). Same effect but might save a cycle or two. []https://www.ubbdev.com/threads/php/images/icons/wink.gif[/]

Sponsored Links
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
Nice one Gossip! Thanks for sharing, I'll add this to my test forum and try it out []/forum/images/icons/smile.gif[/]


- Allen wavey
- What Drives You?
tgnb #214156 03/09/2002 3:11 PM
Joined: May 1999
Posts: 149
Enthusiast
Enthusiast
Offline
Joined: May 1999
Posts: 149
Working beautifully - much appreciated!
Max

Maze_Brendan #214157 03/09/2002 6:10 PM
Joined: Jan 2002
Posts: 218
Enthusiast
Enthusiast
Offline
Joined: Jan 2002
Posts: 218
Same here!

Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
Nice one... it did trim ~12 queries out of 54 or so on a test forum I have setup locally []/forum/images/icons/smile.gif[/] Thanks []/forum/images/icons/smile.gif[/]


- Allen wavey
- What Drives You?
Sponsored Links

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Ruben Rocha
Ruben Rocha
Lutz,FL,USA
Posts: 254
Joined: January 2000
Forum Statistics
Forums63
Topics37,575
Posts293,931
Members13,824
Most Online6,139
Sep 21st, 2024
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,834
Greg Hard 4,625
Top Posters(30 Days)
Gizmo 1
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2025 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.1
(Snapshot build 20240918)