I have a complex task in sorting my repeating group.
To sort items in my repeating group I use views counter (views are counted with help of plugin ViewPort detector placed in the Rg).
I sort items the way those with less views are automatically displayed above others (Sort views count - Descending - no).
The problem is that I want to make Repeating group items sorted just once on load, because items keep switching places based on views counter because of views added by other users).
Is there a way to sort the rg only once and keep all the items in the same order after initial sorting and load.
You only want to sort the RG by the initial view count on page load, right?
Maybe try this:
1/ Add a new field for initial view count ‘Initial view count’
2/ On page load - make changes to your data source to populate that new field ‘Initial view count’ with the initial view count on page load
3/ Sort by that new field ‘Initial view count’ instead of the other view count field which change constantly
The only thing is that view counter is a number value stored in Product data type.
And to save initial view count on page load I need to process the list of all products on load to save actual view counts to Initial view count field.
And also I need to save processed Initial view count as a list of states and then somehow identify each state from the list with the correct item from rg to sort it.
As I understand, each visitor have its own initial-view-count value, you cannot use single field for all of them. I don’t know simple way to do that… It might be possible with caching, but that’s completely different story. In fact you would still need to fetch the full list one way or another to make sure it’s consistent. The question is how to make it effectively so that user won’t see any delays.
I suggest to re-think business requirement under the hood, there might be some room for optimization.
But sill, it finally depends on you particular case. If you’re building prototype or MVP just to test your business idea, then it’s porbably not mission-critical story, try make static operator on some expected amount of data to look at the performance. Hundreds is not a big deal if structures ain’t large as well as a number of users, but there might be other details I’m not aware… Like number of such lists on a page, complexity of data structures and etc…
There are some Products that are advertised and I tried to make an algorithm for rotation of this products so that they get equal amount of product views, sorting the rg the way products with less views to be displayed on the top of the list.
Maybe you have any ideas on how to achieve that? thanks!
Then just limit the list to some reasonable size (:items unit # or something like that) after sorting and then make it static. I don’t think someone would slide for hundreds of products…
Each time user reloads a page a different subset of products will be displayed, but until then (page load) no updates would affect the list.