PDA

View Full Version : Remove 1 Query Per Page


Trigunflame
02-10-2006, 10:00 PM
[CENTER]Remove 1 Database Query Per Page
Reduce your forums query usage !

Summary: (Quoted From Original Hack for vb3)

Removes 1 Query Per Page.

Instructions:

1. Open includes/class_core.php
2. Go to about line 2538 and look for
$this->set('location', WOLPATH);
3. Above that, paste the following.
$this->set('old_location', $session['location']);
4. Go to about line 2818 and look for the following:
// registered user
if (!SESSION_BYPASS)
{
if (TIMENOW - $this->userinfo['lastactivity'] > $this->registry->options['cookietimeout'])
{
// see if session has 'expired' and if new post indicators need resetting
$this->registry->db->shutdown_query("
UPDATE " . TABLE_PREFIX . "user
SET
lastvisit = lastactivity,
lastactivity = " . TIMENOW . "
WHERE userid = " . $this->userinfo['userid'] . "
", 'lastvisit');

$this->userinfo['lastvisit'] = $this->userinfo['lastactivity'];
}
else
{
$this->registry->db->shutdown_query("
UPDATE " . TABLE_PREFIX . "user
SET lastactivity = " . TIMENOW . "
WHERE userid = " . $this->userinfo['userid'] . "
", 'lastvisit');
}
}
5. Replace that with the following:
// registered user
if (!SESSION_BYPASS)
{
if (TIMENOW - $this->userinfo['lastactivity'] > $this->registry->options['cookietimeout'])
{
// see if session has 'expired' and if new post indicators need resetting
$this->registry->db->shutdown_query("
UPDATE " . TABLE_PREFIX . "user
SET
lastvisit = lastactivity,
lastactivity = " . TIMENOW . "
WHERE userid = " . $this->userinfo['userid'] . "
", 'lastvisit');

$this->userinfo['lastvisit'] = $this->userinfo['lastactivity'];
}
elseif ($this->vars['old_location'] != WOLPATH || THIS_SCRIPT == 'misc' || THIS_SCRIPT == 'online')
{
$this->registry->db->shutdown_query("
UPDATE " . TABLE_PREFIX . "user
SET lastactivity = " . TIMENOW . "
WHERE userid = " . $this->userinfo['userid'] . "
", 'lastvisit');
}
}

Corriewf
02-11-2006, 08:42 AM
Awesome! Thanks!

Trigunflame
02-11-2006, 09:38 AM
Awesome! Thanks!
Welcomez :)

Protoman
02-11-2006, 01:56 PM
think the vB team will add this to the next version??

Zia
02-11-2006, 02:40 PM
* Zia kliks install

Trigunflame :) what is next tremendious idea to make page laod faster & fatser ?

:D

Kihon Kata
02-11-2006, 04:40 PM
INstalled! Thanks! but I am running ministats and I am not seeing a decrease on queries listed in there during page loads.

Trigunflame
02-11-2006, 06:29 PM
Because if you would look at the query:

$this->registry->db->shutdown_query()

It is a shutdown query that is run as the script is ending, and is not shown in any query counters. Nevertheless it is still sending that query to your forums mysql database which affects the system.

I didnt say this would necessarily make your forum "Faster", I just said it would reduce a query, lol.

Go read my thread in vb3 if you dont believe me...

GenSec
02-11-2006, 08:08 PM
/me cliks install

Thank you, very usefull!

GenSec
02-11-2006, 08:24 PM
/me cliks install

Thank you, very usefull!

Trigunflame
02-11-2006, 10:29 PM
* GenSec cliks install


Thank you, very usefull!

Doublepost, might wanna delete one; lol.

Kihon Kata
02-11-2006, 10:32 PM
Because if you would look at the query:

$this->registry->db->shutdown_query()

It is a shutdown query that is run as the script is ending, and is not shown in any query counters. Nevertheless it is still sending that query to your forums mysql database which affects the system.

I didnt say this would necessarily make your forum "Faster", I just said it would reduce a query, lol.

Go read my thread in vb3 if you dont believe me...

Oh, all I said is that when the stats lists, it's the same number of queries listed, that's all. Nothing about speed or "Faster".

Anyhow, thanks for this

Snake
02-12-2006, 09:19 AM
Thank you very much. I always wanted to reduce the query usage on my forums but guess what, this helps a lot! :)

NuclioN
02-12-2006, 09:48 AM
Trigunflame the code to replace at the very bottom of the last replacement says you have to overwrite. That section in the original has this:


$this->registry->db->shutdown_query("
UPDATE " . TABLE_PREFIX . "user
SET lastactivity = " . TIMENOW . "
WHERE userid = " . $this->userinfo['userid'] . "
", 'lastvisit');
}
}
}
}
}


-----------------------

According to the manual i have to overwrite the first two } is that correct?

Trigunflame
02-12-2006, 09:59 AM
Trigunflame the code to replace at the very bottom of the last replacement says you have to overwrite. That section in the original has this:


$this->registry->db->shutdown_query("
UPDATE " . TABLE_PREFIX . "user
SET lastactivity = " . TIMENOW . "
WHERE userid = " . $this->userinfo['userid'] . "
", 'lastvisit');
}
}
}
}
}


-----------------------

According to the manual i have to overwrite the first two } is that correct?

Just replace the php code in the first php example, with the php code in the 2nd example.

NuclioN
02-12-2006, 10:14 AM
Tnx :) Every reduce of query is usefull

o0Hubba0o
02-12-2006, 03:22 PM
3. Above that, paste the below

So does it go above? Or does it go below?

Wait, I think I understand now that I look at what I typed, your saying to paste what's below above this "$this->set('location', WOLPATH); " right? Maybe change it to say: "3. Above that, paste the following:". ;) Otherwise more people might get confused if they're looking at this right after getting up in the morning like me hehe.

Trigunflame
02-12-2006, 08:37 PM
So does it go above? Or does it go below?

Wait, I think I understand now that I look at what I typed, your saying to paste what's below above this "$this->set('location', WOLPATH); " right? Maybe change it to say: "3. Above that, paste the following:". ;) Otherwise more people might get confused if they're looking at this right after getting up in the morning like me hehe.

It doesnt matter if you paste it below it or above it, just a 1 liner.

Trigunflame
02-18-2006, 01:53 PM
*bump*

dutchbb
02-18-2006, 03:24 PM
I'm still not sure what changes when I remove the query. And if it doesn't change speed I rather keep the extra query

Trigunflame
02-20-2006, 07:12 PM
I'm still not sure what changes when I remove the query. And if it doesn't change speed I rather keep the extra query

If you dont care, dont worry about it :tired:

Trigunflame
02-27-2006, 02:18 AM
Gotta love bumps.. but no this really is important...

Oblivion Knight
02-27-2006, 05:09 AM
Is there anything fundamentally changed by this?

The only reason I haven't installed it personally, is because Jelsoft generally do a good job at optimising their code and queries. If they could have originally saved on this query without losing some kind of functionality, I'd be wondering why they didn't.

Trigunflame
02-27-2006, 05:45 AM
Is there anything fundamentally changed by this?

The only reason I haven't installed it personally, is because Jelsoft generally do a good job at optimising their code and queries. If they could have originally saved on this query without losing some kind of functionality, I'd be wondering why they didn't.

Well good thing you asked that actually. I just noticed earlier today that I need to update this hack to reflect a change in 3.5.x that I didnt account for when i ported it from vb3.

It deals with how sessions are updated; before in vb3 it was handled in a single function; now it uses 2 seperate functions for updating the user last active and the session.

So yes, it wont hurt anything to use this small addition.. but it does need to be expanded to deal with the session table as well; which would/could save 2 queries as opposed to the 1.

MissKalunji
03-20-2006, 03:39 AM
Well good thing you asked that actually. I just noticed earlier today that I need to update this hack to reflect a change in 3.5.x that I didnt account for when i ported it from vb3.

It deals with how sessions are updated; before in vb3 it was handled in a single function; now it uses 2 seperate functions for updating the user last active and the session.

So yes, it wont hurt anything to use this small addition.. but it does need to be expanded to deal with the session table as well; which would/could save 2 queries as opposed to the 1.


Waiting on update :)

EasyTarget
03-20-2006, 10:32 PM
hmm... bump

Alien
03-21-2006, 01:32 AM
I'm very interested in this.. I'll wait for update. :)

Trigunflame
03-21-2006, 07:49 PM
Yes.. will be done sometime, lol lots of things on my todo list.

Alien
03-22-2006, 02:00 PM
Look forward to it!

I'm currently running 3.5.4, will this mess up anything regarding sessions or can I still run this one until the other one is out?

Zia
03-23-2006, 06:48 PM
Caching Template...also reduce 1 query.....this also reduce 1 ..
hope to get an update about this(Remove 1 Query Per Page) hack

MissKalunji
03-23-2006, 08:48 PM
Caching Template...also reduce 1 query.....this also reduce 1 ..
hope to get an update about this(Remove 1 Query Per Page) hack


accelerator :P accelerates

and compress less loading

isnt the world perfect now? lol

sure is for me

thanks! Trigunflame (i cant never spell his name right)

Alien
03-24-2006, 12:25 AM
World will be perfect if someone can confirm this doesn't mess anything up in 3.5.4 so i can use it until he updates it further. The "sessions" thing he mentioned made me nervous so wanted confirmation. ;)

MissKalunji
03-24-2006, 12:34 AM
what session thing?

Alien
03-24-2006, 12:38 AM
Umm?

Post #23 in this thread...

Alien
03-26-2006, 08:52 PM
Does anyone have an answer to this question?

Trigunflame
03-27-2006, 10:18 PM
It shouldnt mess up anything.

Alien
03-28-2006, 12:06 AM
Thank you so much!

mark99
06-24-2006, 08:04 AM
Does it work with 3.6?

Skyline_GT
06-24-2006, 08:27 AM
wow thanks. Very useful

rjmjr69
02-10-2007, 09:29 AM
Does this work in 3.6.4?