Why do developers make stupid database queries
@alvarezp
if (user not in foo.filter_bar(User.objects.all()))
@wolf480pl Usually because they have a mismatch between their mental model of how the database system works, and how it actually works.
@jankoekepan hm.. like thinking fetching all users from database is faster than fetching one user?
It can be faster, with some big ifs attached: what's the ratio of internal performance to external IO? Is the data stored in a format that rewards simple streaming of unfiltered datasets with minimal interference? And so on.
Also, it depends on the developer's other purposes: is it part of a function that might be called many times to fetch multiple users, thus motivating fetching lots and caching the data once versus fifty individual calls?
And sometimes they're just wrong.
>or it could be throw-away
that code passed code review by 2 reviewers, including the project lead
@jankoekepan
>is it part of a function that might be called many times to fetch multiple users
No, it's called only once per request.
>Is the data stored in a format that rewards simple streaming?
No, it's a good old relational database, and then they need to do other queries to filter out users who shouldn't be visible.
Then they check if the user specified in URL is in the set of visible users.
@wolf480pl Example?