The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Displaying a random post
Is there a mod which can do this?
So that at the top right of the forum I can have something like this: "<text from a random post>" -<username> -<thread name> I made one myself, but it instead of the pages loading in less than a second, they took about 2 seconds to load, so I turned it off. I used the global_start hook as anything else seemed to be processed too late. Actually, if I post the code maybe someone will be able to help: PHP Code:
|
#2
|
|||
|
|||
Maybe use the datastore to store the post then get a scheduled task to select a new post every 5 minutes or so. You may find it quick to select pre-parsed posts from the postparsed table (if you have post caching on).
Instead of doing multple str_replace()s you can put the search and replace values into seperate arrays. E.g. PHP Code:
|
#3
|
|||
|
|||
Thanks for that! Do you (or others) have any more ideas to make it faster/more efficient?
|
#4
|
|||
|
|||
I could think of a couple ways that might make your query faster without caching. By ordering on rand(), you are forcing a table scan of the entire post and thread tables, because that is the only way mySQL can use to determine which row will be ordered first.
So, the first option I see is to limit the posts by the dateline field. After all, do you really want a random post from any time in your board's history? You might limit it instead to a certain number of days in the past. The second option, is to take advantage of MySQL's super fast row counting on MYISAM tables. You'd use two queries to get your result. The first would do a count of the rows. In PHP, you'd then randomly determine which one you wanted to use. Then execute a second query that used LIMIT $randomRow, 1. That would look something like this: PHP Code:
|
#5
|
|||
|
|||
Wow thanks, that SQL hint really made it faster! Never would have thought 2 queries would better than one!
I also changed this: SELECT count(*) total_posts.... To this: SELECT count(postid) total_posts.... Not sure if using a field rather than * is any 'better'? If you have any more gems let me know |
#6
|
|||
|
|||
I had a horrible thought just now so I typed some html code <blink>hi</blink> into a post, and set the query just to look at that post...
To my horror it was all parsed as html! So if someone had typed some nasty html into a post and waited (and refreshed for several hours) it quite possibly would have done something? I assume if I use: $text = htmlentities($rs['pagetext']); That will be safe? |
#7
|
|||
|
|||
Or if you have vbulletin global file already included, you can just use the vbulletin BBcode parser.
https://vborg.vbsupport.ru/showthrea...ghlight=bbcode |
#8
|
|||
|
|||
Ahh good tip that, and it means I can get rid of my search replace arrays, because this parser does it all for me!
Keep it simple.. |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|