#How do we avoid fetching the user on every page reload
42 messages · Page 1 of 1 (latest)
yes that is
i don't really know what to do to optimize it as much as possible, i don't really need to do much with the data of users
Do you have like several large text fields or something?
in the columns? no large text fields but lots of columns
Okay first let's figure out if it's slow just because you have way too many users or if it's because you're pulling too much data for that one user.
alright, thanks for your help man, where to start?
Add a User::select('idInternaute')->first() to a test route and compare the time it takes to complete that query
alright, be right back
(that should result in a select idInternaute from r_internaute limit 1)
oh sorry forgot to do the where part, php User::where('idInternaute', 185009)->select('idInternaute')->first()
i did that one
and it takes a normal time with other tables
Approximately how many users do you have?
Order of magnitude will do, 1m, 10m, 100m?
+140k
okay definitely shouldn't be that slow if the column is indexed
alright man, i'm not sure it's indexed
If it's the primary key, it should be. Are you using laravel to access a previously existing database or did you create that using laravel migrations?
i'm using Laravel to access a previously existing database
Are you able to run show indexes from r_internaute; on your database?
You can do it through laravel with DB::select('show indexes from r_internaute');
yep
empty result, as i thought
oh my god it wasn't the primary key since this long
it's an old db but still lol, thanks for helping me mate, it should make it way faster now?
Now, to answer your original question, yes, it is possible to not fetch the user on every page reload, but that's generally not a thing you need or really want to do because it involves caching the user and you'd have to wait for the cache to expire if you want to, for example, disable a user's access
And yes, I would be surprised if that query took more than a couple milliseconds now
And that's assuming the database is about as old as the hardware it's running on
that's what i thought yes, complicating it for nothing when i can fix it by making my id the primary key
alright i will test that, thanks a lot, you're a great man
haha
oh shit
Ye
have a great day ahead dude, thanks again