Learn how to properly configure your lists with the CRUD Generator to avoid long loading times.
With PHP CRUD Generator, the loading time of your admin panel READ lists should generally be fast and not exceed a few seconds at most. Abnormally long loading times are either due to the configuration of your filters or the number of queries needed to display the data.
In both cases, the solution is simple to implement using the CRUD Generator. Here is how to proceed to reduce your loading time.
When you add a record filter to your READ list, the program sends the SQL query and retrieves all records from the database. It then generates a select
field that will include as many options as you have records.
This is perfect for a table that contains a few dozen or even hundreds of records, but if your table contains thousands, it will significantly increase the page loading time.
In this case, you need to enable Ajax loading when creating your filter from the CRUD generator.
With Ajax loading enabled, the page will load a simple input
field attached to an autocomplete
plugin. The plugin will fetch the records on demand for auto-completion. This way, you avoid loading heavy and unnecessary data when loading your main page.
When you load a list of records from your database, the program performs the following queries:
If you have enabled external relations, the program will also perform the following queries:
For example, if you have a movie table linked to an actor table and a category table, and you have enabled the display of actor names and categories in the movie list, the program will perform two queries for each movie to retrieve the actor names and categories.
If you display 20 movies per page, you get this:
Total: 42 queries (+ filters)
Usually, even if there are a relatively large number of queries, it won't be a problem because these queries only return a limited number of records. They are therefore efficient and fast. If nevertheless, you have excessively long loading times, you can disable the display of certain external relations in the main list and display them on another page. You can also limit the number of records displayed per page.
This does not concern PHPCG, but directly the structure of your database. Add an index to each field that will be used regularly in your queries. The MySQL engine is faster and more efficient with indexed fields.
To index your fields: