News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

How get last 3 posts in BoardIndex.template.php

Started by iVaka, September 03, 2019, 09:37:18 AM

Previous topic - Next topic

iVaka

Hello, How to get last 3 posts in BoardIndex.template.php

function template_bi_board_lastpost($board)
{
if (!empty($board['last_post']['id']))
echo '
<p>', $board['last_post']['last_post_message'], '</p>';
}


I want to give back as a result - TITLE POST - 3min (Test post - 3min)

Arantor

Last 3 posts per board? Very expensive to do and on even a modestly busy site will make it run slowly.

If however you mean to show last 3 posts at the bottom of the page ike on this site, that's much easier.

iVaka

i want to show the last 3 posts in each category in BoardIndex.template.php

custom php script select?

Arantor

You end up running a database query for every single board you have. This makes the site very, very slow.

iVaka

Quote from: Arantor on September 03, 2019, 12:04:07 PM
You end up running a database query for every single board you have. This makes the site very, very slow.

no problem :)
do you have any idea how it can be done?

Arantor

I do, but I refuse to give out advice that I know will make a forum massively slower. If you have any more than 3 boards, the performance suddenly is a huge drama.

And then you'll tell me you don't have more than 3 boards, and I'll believe you and then build it and then you'll complain how slow it is.

So, no, no help on this because it's a fundamentally bad idea.

njtweb

What does it mean "expensive" to enable an SMF function? Does that mean the person who is asking is going to pay more to their ISP for hosting if it's enabled because more resources will be allocated for the function to work? I saw Kindred mention the same thing.

Arantor

Every operation has a cost - an amount of resources required to make it happen. More operations, especially more complex operations take more resources.

On some setups the extra processing can very literally cost more money depending on what it is doing, but it's a bit more abstract.

In this case for any given number of boards there is a base computational effort required plus a small incremental increase per board. Adding an extra lookup on every board is a substantial increase. Especially as this isn't just in the board index even if it looks like it should be.

njtweb

Quote from: Arantor on September 04, 2019, 04:06:24 PM
Every operation has a cost - an amount of resources required to make it happen. More operations, especially more complex operations take more resources.

On some setups the extra processing can very literally cost more money depending on what it is doing, but it's a bit more abstract.

In this case for any given number of boards there is a base computational effort required plus a small incremental increase per board. Adding an extra lookup on every board is a substantial increase. Especially as this isn't just in the board index even if it looks like it should be.

Great explanation, thank you. Very informative. Wouldn't have ever known this. :)

Advertisement: