onOffice-Web-Org / oo-wp-plugin

onOffice for WP-Websites
https://wp-plugin.onoffice.com
GNU General Public License v3.0
9 stars 9 forks source link

Backend Performance #701

Closed fredericalpers closed 5 months ago

fredericalpers commented 7 months ago

Initiative

Optimize backend performance for the onOffice for WP-Websites Plugin.

Epic

Analyse and improve the performance of the plugin backend.

User Story

As a real estate agent relying on the onOffice for WP-Websites Plugin, I've experienced performance issues in the backend, particularly when utilizing the Gutenberg Editor and displaying property lists or forms. The presence of redundant database queries and excessive API calls can lead to timeouts and errors. To ensure a fast, reliable and efficient backend experience, I request the optimiziation of the plugin's performance by reviewing and reducing/bundling uncessary API calls and scripts and perhaps implementing a caching mechanism for the backend.

The current backend performance of the onOffice for WP-Websites Plugin reduces productivity, especially when dealing with the Gutenberg Editor and property lists / form displays. The optimization efforts should focus on identifying and rectifying/bundling redundant API calls and scripts to enhance the overall efficiency of the backend.

Tasks

By addressing the performance issues in the backend and implement optimizations, the onOffice for WP-Websites Plugin can offer real estates agents a smoother and more responsive experience, particulalry when working the Gutenberg Editor and managing property lists and forms.

yeneastgate commented 7 months ago

@fredericalpers Here are the preliminary results we temporarily found in this issue:

  • Conduct a thorough audit of existing API calls made by the onOffice for WP-Websites Plugin in the backend

=> Here is a list of APIs Which need optimization:

  • Reduce the number of round trips.

=> This is a list of queries which can be optimized and All functions which can limit the number of calls I see the positions that have complex queries to DB same: Ex: getRecordsSortedAlphabetically, createCustomsLabelsByFormIdQuery, createMultiBaseQuery,...

However, to list "accurately and completely and give more specific details" about "the parts need to refactor". => I need more time to investigate more deeply and respond to you about the estimated time.

  • Review and consolidate JavaScript and CSS scripts utilized in the backend to minimize the number of requests

=> The "consolidate JavaScript and CSS scripts" is resolved at https://github.com/onOffice-Web-Org/oo-wp-plugin/issues/573

  • Address specific performance challenges related to the Gutenberg Editor

In my understanding, the problem you mentioned:

https://github.com/onOffice-Web-Org/oo-wp-plugin/assets/104892108/227b46f3-f0bb-419f-b58f-8adcfbb7cc2e

Please confirm to me whether my understanding of your desire is correct? => So that I can continue to investigate and give you our plans and solutions to introduce the cache correctly.

fredericalpers commented 7 months ago

@yeneastgate please go ahead and try to optimize all APIs and investigate further on which queries can be optimized. As mentioned in our meeting we specifically face problems when using the Gutenberg Editor and it's preview. Therefore we want to implement caching. Any other suggestions for performance improvements are also welcome. Thank you :)

yeneastgate commented 7 months ago

@fredericalpers Now, this result for my investigate: 1.List of APIs that need to be optimized image

2.Here is the list of queries that need to be optimized Note: I used the "query monitor" plugin to identify Slow Queries instead of manual image

3.For Introduce a caching mechanism for the backend => I have found a caching mechanism 'Object Caching' that may be useful for improving the backend performance. However, I need implement emulator this mechanism thoroughly before determining its feasibility and effectiveness. We will continue to investigate when this issue continues."

fredericalpers commented 6 months ago

@yeneastgate please keep investigating, thank you

yeneastgate commented 6 months ago

=> I have found a caching mechanism 'Object Caching' that may be useful for improving the backend performance. However, I need implement emulator this mechanism thoroughly before determining its feasibility and effectiveness. We will continue to investigate when this issue continues."

@fredericalpers After investigating:

  1. The mechanism to load the "Gutenberg editor" of the backend WP is called "Editor Blocks" Rest API (https://developer.wordpress.org/rest-api/reference/blocks/) =>Solutions for optimize performance: I will Introduce a caching mechanism for "Editor Blocks" Rest API to the database.

  2. I have implemented this solution at the "43305-backend-performance-v2" branch, and the performance results are presented below. image

fredericalpers commented 6 months ago

@yeneastgate Are those results only including the caching mechanism or also other API optimizations?

yeneastgate commented 6 months ago

@fredericalpers this results only for the caching mechanism.

fredericalpers commented 6 months ago

@yeneastgate do you think we can improve the performance more through API call optimization or should we move this part to a different issue?

yeneastgate commented 6 months ago

@fredericalpers

do you think we can improve the performance more through API call optimization

  • According to my prediction, Backend Performance can only be improved slightly through "API call optimization".
  • I will let you know the exact change number after I implement a test branch.

should we move this part to a different issue?

  • I think this is not necessary because all solutions have the same purpose to improve Backend Performance
yeneastgate commented 6 months ago

@fredericalpers

  • According to my prediction, Backend Performance can only be improved slightly through "API call optimization".
  1. I have implemented this solution at the "https://github.com/onOffice-Web-Org/oo-wp-plugin/tree/43305-backend-performance" branch, and the performance results are presented below (the loading time decreased from 20,38s to 16,18s) image

  2. While implementing "improve the Backend Performance more through API call optimization". I found "another case" where we can optimize to improve Backend Performance.

Currently, the logic gets the page ID for "Pages using the shortcode". We need to handle two actions in core WordPress ('save_post' and 'wp_trash_post').

However, in the current code, the logic of this part is always called even when the End User does not use the behavior "update page" (save_post) and "trash page" ( wp_trash_post)

=> Solution: We will only load "the logic to get the page ID for 'Pages using the shortcode'" when the End User uses the behavior "update page" and "trash page"

=> I tried implementing in this branch "https://github.com/onOffice-Web-Org/oo-wp-plugin/tree/43305-backend-performance", and here are the results (the loading time decreased from 24,05s to 2,62s) image

Please let me know your opinion about this. Thanks!

yeneastgate commented 6 months ago

@fredericalpers To give you an overview of the changes in Backend Performance, I'd like to list the following improvements:

  1. The caching mechanism for "Gutenberg editor", the loading time decreased from 14.16s to 13.52s.
  2. Through API call optimization and query optimization, the loading time decreased from 20.38s to 16.18s.
  3. Will only load "the logic to get the page ID for 'Pages using the shortcode'" when the End User uses the behavior "update page" and "trash page", the loading time decreased from 24.05s to 2.62s.

Note: We have clearly stated details about each solution in the comments above.

fredericalpers commented 6 months ago

@yeneastgate This seems to be promising, thank you :) I will get back to you asap.

fredericalpers commented 6 months ago

@yeneastgate please go ahead and create the pull requests :) thank you

yeneastgate commented 6 months ago

@fredericalpers I created a PR that includes the logic of the following solutions:

  1. We will only load "the logic to get the page ID for 'Pages using the shortcode'" when the End User uses the behavior "update page" and "trash page" => Loading time of "Gutenberg editor" in the edit screen decreased from 25.6s to 2.5s image

  2. Through API call optimization and query optimization => In this PR, we refactored the logic code of the screens: Estate List, Unit List, and 4 forms (Contact, Interest, Owner, Applicant Search). => The loading time of the Estate List has been decreased from 15.06s to 13.46s The loading time of the Owner Form has been decreased from 15.73s to 14.03s image

    image

Note: During retesting:

  1. I realize that the logic of the solution caching mechanism for "Gutenberg editor" has many potential errors because we are caching WP's Rest API and this does not increase performance much (as reported in the comment above https://github.com/onOffice-Web-Org/oo-wp-plugin/issues/701#issuecomment-1888792166) => So I think we should not merge this logic into the PR
  2. Optimizing performance for the load preview of "Gutenberg editor", we have reduced it significantly with solution 1 (only load "the logic to get the page ID ) above
BenjaminZekavica commented 5 months ago

@dai-eastgate @yeneastgate, here's some information about our WP blocks:

andernath commented 5 months ago

@yeneastgate and @dai-eastgate we will discuss, if Preview Mode of ACF Fields is necessary for the first steps. I will contact you later.