Log message #4188701

# At Username Text
# Jun 6th 2019, 20:19 ckjksl lol. i have a wee bit of leeway because it's a local app and only 1 user at a time
# Jun 6th 2019, 20:18 jeremyharris might work well for 2k rows, might not for 1 billion :P where as rand in the query might work better for 1 billion over 2k (though I doubt it)
# Jun 6th 2019, 20:17 jeremyharris it’ll be up to you to figure out the most optimized way to do this depending on your data. for example, you can fetch all IDs only, don’t hydrate, get a random one within PHP, and do a quick SELECT on it
# Jun 6th 2019, 20:17 ckjksl lol okay, i'll try that
# Jun 6th 2019, 20:16 jeremyharris if contain doesn’t work with rand/limit, you can always make a new query for the random result and slap it on the entity :)
# Jun 6th 2019, 20:16 ckjksl but 2500 tags with associated assets is a 20 second page load :(
# Jun 6th 2019, 20:15 ckjksl for me, $q->order('random()') returns all associated data randomized.
# Jun 6th 2019, 20:15 jeremyharris perhaps try a subquery instead?
# Jun 6th 2019, 20:15 ricksaccous and he can't first() in a contain()
# Jun 6th 2019, 20:15 ricksaccous i didn't type that out right
# Jun 6th 2019, 20:14 ricksaccous yeah that's what i gathered, but it seems limit on order->rand() returns nothing
# Jun 6th 2019, 20:14 jeremyharris I think what lorenzo meant by that comment in the SO post is that rand doesn’t perform well regardless of how you try to optimize it at the query
# Jun 6th 2019, 20:13 jeremyharris grabbing them all and randomizing within PHP isn’t great, because all that data needs to come back from the database and get turned into PHP objects, which could be memory intensive
# Jun 6th 2019, 20:12 ricksaccous oh it does?
# Jun 6th 2019, 20:12 ricksaccous or closest to the randomized id
# Jun 6th 2019, 20:12 jeremyharris limit works on rand
# Jun 6th 2019, 20:12 ricksaccous just randomize the id and grab by the randomized id XD
# Jun 6th 2019, 20:11 ckjksl yeah. So i guess i might as well grab all of them and splice them myself
# Jun 6th 2019, 20:11 ricksaccous doesn't matter, it seems that limit won't work on rand() in general because rand() grabs all then splices them
# Jun 6th 2019, 20:11 ricksaccous oh you mean in the example?
# Jun 6th 2019, 20:05 ckjksl that's not even the associated data. it's the regular data.
# Jun 6th 2019, 20:04 ckjksl wow. okay, maybe i'll just do that then -.-
# Jun 6th 2019, 20:04 ricksaccous if you really need random might as well just grab them all then
# Jun 6th 2019, 20:03 ricksaccous Using RAND() is always horrible, as it needs to get all results, order them randomly and then slice the results. Regarding your question, firstOrFail will apply a LIMIT 1 for you. That does not mean that RAND() will perform faster, though.
# Jun 6th 2019, 20:03 ricksaccous oh wow @ckjksl https://stackoverflow.com/questions/28348297/how-do-i-get-a-random-row-in-cakephp-3-0
# Jun 6th 2019, 20:02 ricksaccous might have to do with weird quote escaping things
# Jun 6th 2019, 20:01 ricksaccous that will give you the best idea of how to fix it
# Jun 6th 2019, 20:01 ricksaccous or to just get the SQl from the query
# Jun 6th 2019, 20:01 ricksaccous and see the query cake is trying to run
# Jun 6th 2019, 20:01 ricksaccous i mean prob best way to debug it is to look at your query log
# Jun 6th 2019, 19:59 ckjksl in the function($q), it works fine if i just leave it as ->order('random()') without ->first() or ->limit(1)
# Jun 6th 2019, 19:54 ckjksl i know, it's weird. I'm not sure what's going on either. I'm just going by my error.log
# Jun 6th 2019, 19:50 ricksaccous also you shouldn't have to specify enableAutoFields if you never manually selected in the first place
# Jun 6th 2019, 19:50 ricksaccous yeah, heh
# Jun 6th 2019, 19:49 ricksaccous that is what you were referring to
# Jun 6th 2019, 19:49 ricksaccous oh
# Jun 6th 2019, 19:49 ricksaccous just to see if it works with manually selecting fields
# Jun 6th 2019, 19:49 ricksaccous on the contained model
# Jun 6th 2019, 19:49 ricksaccous oh i meant
# Jun 6th 2019, 19:46 ckjksl but i guess i might have to =D
# Jun 6th 2019, 19:46 ckjksl some of these tags have thousands of assets associated. I'd rather not retrieve all of them first and pick one if i don't have to.