Improvement of categorytree api issue


Download 8.06 Kb.
Sana14.12.2022
Hajmi8.06 Kb.
#1004017
Bog'liq
improvement-of-categorytree-api (2)


Improvement of categorytree API
Issue
API returns full tree of categories and products from PrestaShop database to be used in mobile application. That’s why upon high load its response time is up to 10 seconds which is not acceptable.
Api response time shouldn't be more than 1 second
In communication with Axror (mobile developer) it has been found that mobile application really uses almost all data of all products and all categories. The problem is that communication was messed, Axror did not provide formalized response, as it was requested by Kamil, and his English is not very good. So, Kamil is not 100% sure yet that all products data are really needed by mobile application.
That’s why we will try 2 solutions gradually to be sure that all works.
Preparation to the solution
Ask Axror to implement in test version of mobile application usage of API endpoint “categorytree-v2” instead of “categorytree”. Do not upload fixed mobile app to app store yet! It is just for testing.
Solution #2
a) Create new module OR console script that performs caching of category tree with all products
Create new table kash_categorytree in the database with the following fields: id, is_category, num_of_products, parent_id, data (longtext), update_date (taken from JSON further).
If you know how to implement console scripts that use PrestaShop logic then separate module is not needed. But if it is impossible or if you don’t know how to do it (I don’t know, for example) then create new separate module with a single controller.
Put into this script/controller the logic from categorytree API. The resulting JSON array then must be parsed with a separate logic explained further.
Walk through all this tree in JSON and save each of category/product in separate record of that new table. Update date should be taken from date_add/date_update (or similar fields in JSON). To minimize writing to the table we must update only products/categories with changed update/add dates and changed number of products in category.
If you implemented the logic as module controller, then we must protect it against running from the web. It will be done in several ways used together: a) obfuscate controller name by adding random set of characters to the end, for example KUF554yFKFY6kdlo etc. b) inside code of controller check with $_POST[“secret”] variable is submitted and it has value taken from configuration script that is located outside of web directory in new /kash-caching/configuration.php
b) If logic above was implemented as new module/controller…
Then create runner of this logic in /kash-caching/runner.php This script should access the new controller by web URL https://optom.app/bla-bla-bla/new-module-controller-KUF554yFKFY6kdlo-etc and send there as $_POST secret value from configuration.php
Configure runner.php to be executed once per 4 hours.
Check that it really runs the required logic and all tree is cached in custom table.
c) Implement new categorytree-v2 API that loads data from kash_categorytree table
Instead of loading all tree with PrestaShop methods, it should load cached data from new table and compile them as JSON.
Ask Kamil to review all.
Upload new files on server manually.
Check with Axror and in Postman that response time for this API is reasonable, about 1 second or so.
Additional performance improvements
The next steps for improving performance include the following:
a) cleaning JSON cached in kash_categorytree table to remove fields unused by Axror, as I explained above Axror does not give formalized responses, so you may need to to talk a lot with him and Azizjon about every field;
b) create new field is_update_required in kash_categorytree table; create separate module with multiple hooks on addition/update of categories/products in the database; set is_update_required to 1 in these hooks if something is changed; reconfigure runner.php to run ever 5 minutes and check presence of 1 in this field; so update of cached categorytree will be performed only if it is really necessary.

Page of

Download 8.06 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling