#How do we avoid fetching the user on every page reload

42 messages · Page 1 of 1 (latest)

turbid kettle
#

That's an obscene time for a single query, is that the primary key of the table?

undone copper
#

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

turbid kettle
#

Do you have like several large text fields or something?

undone copper
turbid kettle
#

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.

undone copper
turbid kettle
#

Add a User::select('idInternaute')->first() to a test route and compare the time it takes to complete that query

undone copper
#

alright, be right back

turbid kettle
#

(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()

undone copper
#

yep still around 60-80ms

turbid kettle
#

hmm

#

It's weird that it would be this slow

undone copper
#

and it takes a normal time with other tables

turbid kettle
#

Approximately how many users do you have?

#

Order of magnitude will do, 1m, 10m, 100m?

undone copper
#

+140k

turbid kettle
#

okay definitely shouldn't be that slow if the column is indexed

undone copper
#

alright man, i'm not sure it's indexed

turbid kettle
#

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?

undone copper
turbid kettle
#

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');

undone copper
#

empty result, as i thought

turbid kettle
#

Great, easay fix then

#

Just make that your primary key

undone copper
#

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?

turbid kettle
#

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

undone copper
undone copper
turbid kettle
#

Ye

undone copper
#

have a great day ahead dude, thanks again