Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Searching for locations is slow #1300

Closed
Tracked by #790
mahalakshme opened this issue Aug 1, 2024 · 4 comments
Closed
Tracked by #790

Searching for locations is slow #1300

mahalakshme opened this issue Aug 1, 2024 · 4 comments
Assignees

Comments

@mahalakshme
Copy link
Contributor

mahalakshme commented Aug 1, 2024

Issues:

Loading of locations takes more time in all the places. By the time the results display the user loses patience and moves away from the page.
Env: prod, org name: Goonj

  1. In Distribution registration form in DEA,

https://{domain_name}/locations/search/find?title=a&typeId=1396&size=100&page=0 - taking 23 secs in DEA
Screenshot 2024-08-14 at 12 15 11 PM

  1. In Admin tab, on clicking a test catchment the already set locations to display takes a minute

https://{domain_name}/locations/search/findAllById?ids={someLocationId} - took 37 secs - fired to fetch the location name already added

https://{domain_name}/locations/search/find?title=&page=0&size=1000&sort=id%2CDESC - took 1.6 min - fired to show a list of locations

https://{domain_name}/locations/search/find?title=ab&page=0&size=1000&sort=id%2CDESC - took 1.9 min - fired as I typed a location name to show the appropriate search results - to add the location starting with ab to the catchment

Screenshot 2024-08-14 at 12 28 24 PM

AC:

The location search and save should be smooth. So the above API calls should not take more than a second or two.

Root cause:

Joining with title_lineage_locations_view

Technical solution - suggestions:

  • Why cant we have the title_lineage in address_level table itself - none of the advantages that view provides seem to be relevant for us w.r to title_lineage_locations_view - one additional thing need to do is, whenever lineage(ids) are updated, this also needs update. But considering updating hierarchy is not as frequent as location search, priority for efficiency of location search seems to be important.
    • If this is done, need to fix all the queries where we do join with title_lineage_locations_view
    • The in-memory search done on title_lineage_locations_view to optimise individual search via DEA might not be needed.
  • for DEA registration form this might help: In hierarchical location setting search - When parent_id is passed need not join with title_lineage_locations_view since the user will know the parent - applicable for DEA search ie. need not show the dropdown list with hierarchies.

Reason for priority:

  • Currently API search of individual is very slow - one reason is join with title_lineage_locations_view. Fixing the above, will help in fixing everywhere in a uniform way wherever we do join with title_lineage_locations_view.

Old: Ignore:

Below might help:

  • For adding location to catchment, and in DEA search this might help: From the plan(explain analyse result) realised that, left join with title_lineage_locations_view in locationProjectionBaseQuery is the bottleneck. Hence, adding an index on lowest_point_id column might help.

Old

  • adding an index to name column in address_level table. Also joint index of typeId and parentId columns.
  • debouncing the API call in type-ahead functionality - doesn't seem to be done in Admin app search
  • Instead of 1000 returning 100 results might be sufficient.
  • Inner join instead of left join in locationProjectionBaseQuery to minimise the number of matching rows

Questions:

If joining with the view is the problem, then we can add a separate below UI in the locations page, to be able to mention the hierarchy instead of searching across all the hierarchy. This hierarchical on DEA and Admin can get enabled on when the number of locations exceeds a particular no.

@mahalakshme mahalakshme reopened this Aug 1, 2024
@mahalakshme mahalakshme changed the title Editing a catchment via Admin tab slow Searching for locations is slow Aug 14, 2024
@1t5j0y 1t5j0y self-assigned this Aug 29, 2024
1t5j0y added a commit to avniproject/avni-server that referenced this issue Aug 30, 2024
@1t5j0y
Copy link
Contributor

1t5j0y commented Aug 30, 2024

  • Continuing with in-memory search approach for title lineages as the computation of title lineages happens for all records when queried via join whereas it is sufficient for us to compute it for a specific page.
  • Not introducing column to store title lineages in address_level as they will need to be updated whenever a location name changes in addition to hierarchy changes.

Pending:

  • join with title_lineage_locations_view slowing down user subject assignment screen.

QA Notes:

  • Web App - DEA
    -- Location form element in both hierarchical and non-hierarchical mode (org config setting toggle 'Show hierarchical location')
  • Web App - Admin
    -- Locations page
    -- Locations search
    -- Catchments show
    -- Catchments add locations
  • Web App - Tasks
    -- User subject assignment search

1t5j0y added a commit to avniproject/avni-server that referenced this issue Sep 2, 2024
…nce improvement

- removed join to title_lineage_locations_view
@petmongrels
Copy link
Contributor

We should remove - String getTitleLineage() from the interface LocationProjection. It is going to be misleading.
We are not serialising it anywhere.

Also remove null as titleLineage also from the queries.

@himeshr
Copy link
Contributor

himeshr commented Sep 20, 2024

Testing notes

Following functionality works as expected.
The performance issue was tested on Staging Env, Goonj Revamp(Gpart) organisation.

  • Admin app:
    • Both Location search load and edit are faster
    • Catchment show, Location Load, add / modification are much faster and easy.
  • DEA :
    • Search Page, Non-Heirarchial Location search loads and works faster
    • Address selection during Register is much faster
  • User subject assignment - Address filter location search is fast (Lahi org)

1t5j0y added a commit to avniproject/avni-server that referenced this issue Sep 23, 2024
@mahalakshme
Copy link
Contributor Author

@1t5j0y does the above fix make DEA search also faster.

Screenshot 2024-09-27 at 7 24 04 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

5 participants