0

First of all, I want to make a system that instantly pulls some data using Laravel. For example: Think of it like Coin Prices. I want to fetch the values of 20 different coins from 5 different exchanges on every page refresh. Actually, I don't have a problem with this. My exact problem. Very Slow Receiving Data from API. Normally, the Api resource given to me opens in a short time, but while I try to pull every data, I make a query again. And it runs 5*20 100 queries on each page refresh. And Because of That I'm Getting Both Slow and Error. How Can I Solve This. So I want to take the data once and fill the table over it. I don't want to pull over and over for every transaction. I hope I was able to explain my problem. Thank you in advance for your interest and concern.

The Class I'm Using Is " Illuminate\Http\Request;"

View Functions

I TryI Couldn't Do Anything About It. Sends Multiple Requests to the Same Address Every Time


Edit

The mistake I made: by writing a helper, it was reading data from the api for each data, for each point, briefly for everything. Instead of doing it directly on the blade page, I defined it in my controller and directed it to the blade page and because it calls each data once, my problem was solved, thank you everyone.

  • 1
    If you are fetching data from table that has relationships with other table, make sure to adopt eagre loading and pagination for faster queries **eagre loading** https://laravel.com/docs/9.x/eloquent-relationships#eager-loading **pagination** https://laravel.com/docs/9.x/pagination#basic-usage – ket-c Dec 13 '22 at 12:58
  • Thank you very much for your reply. So how can I use this with guzzle/http. So I am pulling api from an External Source. – Lütfullah Öztürk Dec 14 '22 at 04:39
  • Welcome to SO, would you update your question and bring pictured code and post straight into your question? – wruckie Dec 20 '22 at 04:30

1 Answers1

0

First, I would take all data that is not related to the display, out of the blade and put maybe in the controller/service/model depends what it does.

Second thing, you should try to load some data with eager loading so you don't pull all data separately each time (if you are getting something from the database).

If you have API with a lot of JSON objects then you could take it all, chunk, and then check if that result exists in the table, take the next one, and if not, store it.

devsead
  • 312
  • 7