Hi,
I created the plugin "Random Entries". This Plugin displays a configurable number of random old entries in the sidebar.
You can get it here.
regards,
Christian
Show Random Entries in Sidebar
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: Show Random Entries in Sidebar
Hi!
Thanks for sharing your plugin!
Here are a few thoughts:
One problem of the plugin is that it queries the 'entries' table directly instead using the s9y function 'Serendipity_fetchEntries'. This should be done to also use privileges on which articles a user is allowed to read/access.
Another thing is that you seed the random generator everytime inside the while() loop. Seeding is only required once.
I would also recommend not doing a SQL query within a loop, because this doesn't scale so well. Instead, fetch the title already with the ID together, if possible. Maybe even using caching.
Actually, the problems you have only occur because SQLite and pgsql do not support the MySQL "ORDER BY RAND()" functionality. If one could use that, it would be much better. Using your approach to fetch everything into PHP scope and sort it there is really bad in terms of performance.
Last but not least, I would recommend patching the functionality into the existing plugin "Recent Entries" that comes with serendipity, because that plugin would only need a "randomize" function and could then offer more flexibility.
Maybe on MySQL systems you can rewrite the code to use 'ORDER BY RAND' and only use your method as a fallback for pgsql/sqlite?
Regards,
Garvin
Thanks for sharing your plugin!
Here are a few thoughts:
One problem of the plugin is that it queries the 'entries' table directly instead using the s9y function 'Serendipity_fetchEntries'. This should be done to also use privileges on which articles a user is allowed to read/access.
Another thing is that you seed the random generator everytime inside the while() loop. Seeding is only required once.
I would also recommend not doing a SQL query within a loop, because this doesn't scale so well. Instead, fetch the title already with the ID together, if possible. Maybe even using caching.
Actually, the problems you have only occur because SQLite and pgsql do not support the MySQL "ORDER BY RAND()" functionality. If one could use that, it would be much better. Using your approach to fetch everything into PHP scope and sort it there is really bad in terms of performance.
Last but not least, I would recommend patching the functionality into the existing plugin "Recent Entries" that comes with serendipity, because that plugin would only need a "randomize" function and could then offer more flexibility.
Maybe on MySQL systems you can rewrite the code to use 'ORDER BY RAND' and only use your method as a fallback for pgsql/sqlite?
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Re: Show Random Entries in Sidebar
ok was not sure about that. Fixed.garvinhicking wrote: Another thing is that you seed the random generator everytime inside the while() loop. Seeding is only required once.
Done. I am not sure how to implement caching.garvinhicking wrote: I would also recommend not doing a SQL query within a loop, because this doesn't scale so well. Instead, fetch the title already with the ID together, if possible. Maybe even using caching.
Done. My Patch for serendipity_plugin_recententries can be found heregarvinhicking wrote: Maybe on MySQL systems you can rewrite the code to use 'ORDER BY RAND' and only use your method as a fallback for pgsql/sqlite?
Regards,
Christian
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: Show Random Entries in Sidebar
Hi!
I just looked up the documentation, and it seems both SQLite and postgresql support the "ORDER BY RANDOM()" facility.
So I reworked your patch a bit and committed it:
http://svn.berlios.de/viewcvs/serendipi ... 17&r2=1716
Maybe you could try if it still works?
Regards,
Garvin
I just looked up the documentation, and it seems both SQLite and postgresql support the "ORDER BY RANDOM()" facility.
So I reworked your patch a bit and committed it:
http://svn.berlios.de/viewcvs/serendipi ... 17&r2=1716
Maybe you could try if it still works?
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Cool, I did not know that. Next time I need to read the SQL-specs more carefully...I just looked up the documentation, and it seems both SQLite and postgresql support the "ORDER BY RANDOM()" facility.
Ok, there was one simple syntax error:So I reworked your patch a bit and committed it:
http://svn.berlios.de/viewcvs/serendipi ... 17&r2=1716
Maybe you could try if it still works?
Code: Select all
--- serendipity_plugin_recententries.php.1.7.web 2007-06-10 18:39:18.762815600 +0200
+++ serendipity_plugin_recententries.php 2007-06-10 18:39:51.395245100 +0200
@@ -160,13 +160,13 @@
$dateformat = '%A, %B %e %Y';
}
if ($randomize)
- if ($db == 'mysql' || $db == 'mysqli')) {
+ if (($db == 'mysql') || ($db == 'mysqli')) {
$sql_order = "ORDER BY RAND()";
} else {
// SQLite and PostgreSQL support this, hooray.
$sql_order = "ORDER BY RANDOM()";
}
- } else {
+ else {
$sql_order = "ORDER BY timestamp DESC ";
}
Thanks for you help and your work on serendipity.
regards,
Christian
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
Great, thanks for that catch, also just committed. And thanks for the kind words, I do my best.
Thanks again for contributing to Serendipity!
Regards,
Garvin
Great, thanks for that catch, also just committed. And thanks for the kind words, I do my best.
Thanks again for contributing to Serendipity!
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
- Regular
- Posts: 17
- Joined: Sun May 20, 2007 9:05 am
- Contact:
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
The recent-entries plugin is bundled with serendipity, so it can't be found in Spartacus but only in the release tarballs...
HTH,
Garvin
The recent-entries plugin is bundled with serendipity, so it can't be found in Spartacus but only in the release tarballs...
HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/