joe_g Posted September 15, 2022 Share Posted September 15, 2022 Hi there, I'm trying to achieve randomizing a large set of pages that needs pagination. It could happen every night or so. I know sort=random doesn't work with pagination so I thought, if I can randomize the position of the pages in the actual backend this could work. This might be a heavy operation, but I also wouldn't know how to do it so it's effective. There is the https://github.com/kixe/PageMove PageMove. plugin that could to this with the method sortChildren(). This plugin doesn't seem to be present in the store. But, in the forums there is mentions of this function being built in to v 3.0, but I can't find the docs for that. Would you know the best way to go about this? thanks! J Link to comment Share on other sites More sharing options...
bernhard Posted September 15, 2022 Share Posted September 15, 2022 Could you pleas tell us why you want to do that to get a better understanding of the context? Also, what do you mean by "a large set of pages"? 1 Link to comment Share on other sites More sharing options...
joe_g Posted September 18, 2022 Author Share Posted September 18, 2022 I have ~800 things (in this case published texts) that needs to be shown in random order. It's about 20-50 pages or results, depending how many I show per page. Preferably the randomization stays the same, so a refresh (or a page change) doesn't ruin the order. Link to comment Share on other sites More sharing options...
Jan Romero Posted September 18, 2022 Share Posted September 18, 2022 If you’re running MySql 8 you can use the row_number window function: update pages p inner join (select id, row_number() over (partition by parent_id order by rand()) - 1 as randomsort from pages where parent_id = :YOUR_PARENT_ID) as r on r.id = p.id set p.sort = r.randomsort There may be faster ways to give consecutive sort numbers to random children, but this runs in the blink of an eye (Adminer says 0.005s for my 986 pages). Repeat until you get the order you like. Make sure you set the parent to “manual drag-and-drop” or you won’t see any effect. 1 Link to comment Share on other sites More sharing options...
joe_g Posted September 19, 2022 Author Share Posted September 19, 2022 @Jan Romero Wow, interesting. Thanks, will try this! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now