# exposed

Marcin Wisniowski

05/17/2018, 12:01 AM
This might be a stupid question, but is this code ok?
User.find { Users.confirmed eq true }.sortedBy { it.loginTimestamp }.take(10)
It works, but is it efficient or does it load all users from the database? I'm not sure if the limiting and sorting is done inside the database, or in my code, it looks like it's done in my code, but I want it to happen as part of the query.


05/17/2018, 9:23 AM
Yes, your code will load all confirmed users, load them in memory, sort and then take 10. If you want to make it on DB side:
Copy code
User.wrapRows( { Users.confirmed eq true }.orderBy{ Users.loginTimestamp }.limit(10)

Marcin Wisniowski

05/17/2018, 12:23 PM
Aha! Thank you again. 🙂