ssi_recentPosts sometimes returns null

Started by jjsmith, November 07, 2014, 07:38:17 PM

Previous topic - Next topic

jjsmith

Hi,

I use ssi_recentPosts(1, null, $guest_boards, '') to get the latest post and display on my site.

note - $guest_boards is an array of board id's.

Question - Is there a reason why this would return null?

Sometimes it does return null and I have no post to return.  Does it limit it's "recent-ness" to some time limit, eg the last hour or something like that?

Thanks

JBlaze

The only reason I can think of as to why it would return null is that you are requesting only one recent post, which if that post is in a topic/board that the viewer could not otherwise see, will not be displayed.
Jason Clemons
Former Team Member 2009 - 2012

Arantor

There is the exclusion clause that tries to restrict the subset of the table it looks as to keep it fast:

'min_message_id' => $modSettings['maxMsgID'] - 25 * min($num_recent, 5),

If there's been a bunch of posts in boards other than the selected, it's quite possible this would be null. Bumping the 25 would slow it down a shade but reduce the nullness.

JBlaze

Jason Clemons
Former Team Member 2009 - 2012

jjsmith

Arantor -

I don't understand - why would that would cause the null, or why bumping 25 would fix it.  Do you mind explaining that in a bit more detail?

Thanks

Arantor

If you ask for 10 most recent posts, and your highest message id is 1000, say, it is only going to be looking at messages with ids 875 to 1000. If all of those posts happen to be outside of the boards you request, you get null.

Bumping the 25 raises the range it will consider.

jjsmith

Thanks for the quick reply.

But sorry ... I'm still not getting it. 

I was thinking this function was pretty simple - return the 'n' most recent posts from the given list of "include boards". 

But it sounds like what you're saying is that ... it gets 'n' most recent posts selecting from *all* boards, and then returns any from that list that are in the "include boards".  If none of the posts are in the include boards, then null is returned.  Is that correct?

Arantor

No, that's not correct. I thought I had explained what goes on.

It always filters by the list of boards you specify. Except it ALSO filters to the 125 most recent posts TOTAL as a starting point (since the smaller of 5 and 10 is 5, and 5 * 25 = 125) to avoid hurting performance (since it's much easier to filter out 90%+ of the list before you start before doing anything more selective)

So if the last 125 posts aren't in the boards you asked for, you get null. Which is what is happening here.

jjsmith


Ah - I see -

So by " ... filters to the 125 most recent posts TOTAL as a starting point ..." - does that mean regardless of which board those 125 posts are posted to?


Arantor


jjsmith


I see - so I was correct when I said "...If none of the posts are in the include boards, then null is returned."

Thanks for confirming my analysis.


Arantor

No, your analysis is still wrong unless you were simply very, very unclear in what you meant by 'n' when requesting 10 most recent posts.

Your analysis is: return 10 most recent posts from all boards, then see if they match the list of boards stated in ssi_recentPosts call.

What actually  happens is: return 125 most recent posts from all boards, then look in those 125 posts to match the 10 most recent against the stated boards.

jjsmith


That's ok - no problem - I guess you had to work through your explanation.

I suggest that you update the function documentation -

http://support.simplemachines.org/function_db/index.php?action=view_function;id=514;smf_version=2.0+Beta+3+Public

to include your explanation.

Thanks!

Arantor

Excuse me? I know precisely what I meant since I checked the code before I said anything.

jjsmith


Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: