Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong article order in combination of random ordered article and the article pagination #16081

Closed
stefano-buscaglia opened this issue May 17, 2017 · 15 comments

Comments

@stefano-buscaglia
Copy link

stefano-buscaglia commented May 17, 2017

Steps to reproduce the issue

If in my category there are 6 article and the category is set to show only 4 article, than the pagination is show. Well when i clic on second page, the random function randomize all the article, so in the second page i can view article just showed in the first page and some article that are supposed to be in second page are muved on firts.

On the screenshot 1 there is the first page, the article order is:

  1. A
  2. B
  3. C (note this one)
  4. D

screen shot 2017-05-17 at 14 14 25

On the screenshot 2, after clik on secon page, the article is:

  1. E
  2. C (note this one)

screen shot 2017-05-17 at 14 14 25

Expected result

I expect that the randomization is based on the pagination, so only article that are not showed in the previous page are randomized

Actual result

The randomization do not care about which article is just showed, so one article is showed 2 times (the C) and one in not showed at all (the F, the article are 6).

System information (as much as possible)

database 5.6.35-1dotdeb+7.1
PHP 5.6.30-1
dotdeb+7.1
Joomla! 3.7.0 Stable [ Amani ] 25-April-2017 15:36 GMT
Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT
Template: Beez3 and Protostar

Additional comments

I read this thread:
<http://stackoverflow.com/questions/10729633/php-mysql-pagination-with-random-ordering

as i can understand this depend on the type of SQL query, and the result is a "bug" in the the article pagination.

Please tell me if i need to explain in better way.

Thak you for support our community

S.

@AlexRed
Copy link
Contributor

AlexRed commented May 17, 2017

I can confirm the problem in Joomla 3.7.1


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16081.

@ghost
Copy link

ghost commented May 18, 2017

set Status "Confirmed" in Issue Tracker.

@ggppdk
Copy link
Contributor

ggppdk commented May 18, 2017

Problem is that we need $query->RAND() to order same in subsequent calls of the pagination ...

If accepting that it is proper to have random order per user session

  • meaning a user clicking refresh to a page with random ordering, will see the same random order until user's session is terminated / restarted

We can do this, at places that use:

$query->Rand();

we could use:

// Get shared seed from session, 
$session = JFactory::getSession();
$seed = $session->get('common_query_rand_seed', null);

// Creating seed if it does not exist and store seed into session
if ($seed===null)
{
  $seed = rand();   // 0 to getrandmax()
  $seed = $session->set('common_query_rand_seed', $seed);
}

// Now call a new API method, this is needed since
// some DBs use seperate method for initializing randomizer
$query->setRandSeed($seed);
$query->Rand();
$query->setRandSeed(null);   // Clear it !!

Now DB drivers changes

e.g. for MySQL it would be

public function setRandSeed($seed=null)
{
	$this->seed = $seed;
}

public function Rand($seed=null)
{
	return $this->seed===null
		? ' RAND() '
		: ' RAND('.(int)$seed.')';

}

e.g. for Postgresql no changes to Rand only the newly added setRandSeed($seed=null)

public function setRandSeed($seed=null)
{
	// Use given seed
	if ($seed!==null)
	{
		$this->seed = ((int) $seed) / getrandmax();
	}
	// Effectively we want to re-seed here with a new random number
	else
	{
		$this->seed = rand() / getrandmax();
	}
	pg_query($this->connection, 'SELECT setseed(' . $this->seed . ')');
}

@stefano-buscaglia
Copy link
Author

hi ggppdk,

i'm not sure if i have understood.

  1. The new random function is call the first time the user visit one of the pages of the category (set in random order).

  2. Is it correct even if the page was, for example, the second?

  3. After the user call the new random order, every visit of other pages by click on pagination bar are in the same order?

  4. When user call another page the session in set to null?

Is it correct?

thank you

S.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16081.

@ggppdk
Copy link
Contributor

ggppdk commented May 18, 2017

@stefano-buscaglia ,
my answer was meant for DB developers, to get comments

In short,
in order for query giving the articles to produce same "random" order,
thus pagination will work correctly

It needs to be "seeded" with the same number

e.g. if you use 3 times (3 pages) this

$seed_from_session = 451123;  // some seed stored in session
return ' RAND('.$seed_from_session.')';
return ' RAND('.$seed_from_session.')';
return ' RAND('.$seed_from_session.')';
  • then you will get the same random order for all 3 calls

without a seed if you use 3 times (3 pages) this

return ' RAND()';
return ' RAND()';
return ' RAND()';
  • then you will get a NEW random order on every call, thus pagination will not be working as expected

@ghost
Copy link

ghost commented Nov 7, 2017

@ggppdk can you make a Pull Request?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16081.

@ggppdk
Copy link
Contributor

ggppdk commented Nov 8, 2017

@franz-wohlkoenig

That would mean testing with all supported DBs,
unfortunately, i can not do this now

I have suggested the needed code above for all DBs,
someone with skills for all DBs could do such a PR

@ghost
Copy link

ghost commented Nov 8, 2017

thanks for Info @ggppdk.

Status is set on "Needs Review".

@stefano-buscaglia
Copy link
Author

@franz-wohlkoenig

I also note that the same behavior is present in the pagination of the article for TAG in random order.

If I create a module "Popular - Tag" and I set random order, at any click on the single TAG the order of the TAGs change and this makes it virtually impossible to understand which TAG was just clicked (the user need to remember the name of the TAG instead of the position of the TAG's label.

S.

@ghost
Copy link

ghost commented Nov 9, 2017

@stefano-buscaglia if this is a different Issue please open a new one if there isn't a Issue opened already.

@stefano-buscaglia
Copy link
Author

@franz-wohlkoenig

I think the origin of this issue is the same that cause the problem for the pagination in random order, that, as I can say, is the type of SQL query mentioned here[1] and confirmed by @ggppdk

[1] <http://stackoverflow.com/questions/10729633/php-mysql-pagination-with-random-ordering

@brianteeman
Copy link
Contributor

Thank you for raising this issue.

Joomla 3 is now in security only mode with no further bug fixes or new features.

This is still an issue in Joomla 4 and reading the comments above and on the linked SO discussion I am not sure it can ever be truly resolved and it should be a known issue that any random order will not work as expected when there is pagination.

I am going to leave it open however and ask that the tag is updated for Joomla 4. Who know, maybe it will scratch someones itch and they will work on a usable solution.

@rdeutz rdeutz added J4 Issue and removed J3 Issue labels Aug 26, 2022
@rdeutz
Copy link
Contributor

rdeutz commented Aug 26, 2022

I have changed the label but I don't think this will be fixed at any time. You need to store the data of the shown artikels in the session and then add the already shown artikels as a not in (id1, id2, id3 ...) this will make the site slower. I personally think the random and pagination together makes no sense at all.

@brianteeman
Copy link
Contributor

@rdeutz I agree with you. I almost created a pr to remove random as an option but I can see the value of having random when everything is on a single page.

@Hackwar
Copy link
Member

Hackwar commented Feb 18, 2023

We have now 2023 and this is still open. The way I see it, the randomized order means that on each page load all articles are shuffled again. Yes, that means that pagination doesn't really work, but that is more or less expected behavior. A "static" randomization is not something we offer right now. So this is a WONTFIX and I'm closing the issue. Thank you all for your time and contributions in this discussioon.

@Hackwar Hackwar closed this as completed Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests

7 participants