Jump to content

Widget filefeed sort option RANDOM, is not so good.


SJ77

Recommended Posts

Posted

Hi

I noticed that when creating a downloads block for a file feed sorted randomly that it massively favors older files and doesn't at all look random.

I think I have narrowed down the code driving this behavior to system/Content/Widgets.php

		/* As the block config can try and search all rows in topics/records, etc, we can end up with a tmp table and block nested buffer on members table, so we just query members after separately */
		$skipPerms = ( !isset( $this->configuration['widget_feed_use_perms'] ) or $this->configuration['widget_feed_use_perms'] ) ? static::$skipPermissions : TRUE;
		$items = iterator_to_array( $class::getItemsWithPermission(
			$where,	/* Where clause */
			( isset( $this->configuration['widget_feed_sort_on'] ) and isset( $this->configuration['widget_feed_sort_dir'] ) ) ? ( ( $this->configuration['widget_feed_sort_on'] == '_rand' ) ? $this->configuration['widget_feed_sort_on'] : (  $class::$databaseTable . '.' . $class::$databasePrefix . $this->configuration['widget_feed_sort_on'] . ' ' . $this->configuration['widget_feed_sort_dir'] ) ) : ( $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['updated'] . ' DESC' ), /* Order */

			( isset( $this->configuration['widget_feed_show'] ) AND $this->configuration['widget_feed_show'] ) ? $this->configuration['widget_feed_show'] : 5, /* Limit */
			( $skipPerms ) ? NULL : 'read', /* Permission key to check against */
			$hidden, /* Whether or not to include hidden items */
			$class::SELECT_IDS_FIRST
		) );

However, I don't know how to fix. Can anyone help improve the randomness of this sort option?

Thank you 🙂

Posted

Well, you could change this part

( $this->configuration['widget_feed_sort_on'] == '_rand' ) ? $this->configuration['widget_feed_sort_on'] :

to

( $this->configuration['widget_feed_sort_on'] == '_rand' ) ? 'RAND()' :

but this will likely seriously slow down the widget. If you have a lot of files, it may take a lot of processing power to rebuild the block when the cache expires.

The special "_rand" key uses a substring of the date timestamp to pull a random number, so in most cases it should be sufficiently random while also not being very resource intensive.

Posted
3 hours ago, bfarber said:

Well, you could change this part


( $this->configuration['widget_feed_sort_on'] == '_rand' ) ? $this->configuration['widget_feed_sort_on'] :

to


( $this->configuration['widget_feed_sort_on'] == '_rand' ) ? 'RAND()' :

but this will likely seriously slow down the widget. If you have a lot of files, it may take a lot of processing power to rebuild the block when the cache expires.

The special "_rand" key uses a substring of the date timestamp to pull a random number, so in most cases it should be sufficiently random while also not being very resource intensive.

I know it’s always tricky to pull random data from a resource perspective but the current is Not very random at all. It favors highly the oldest stuff. 
 

switching The order by ‘DESC’ to ‘ASC’

might help? Thoughts?

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...