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

Use Views to load asset/log details #14

Closed
mstenta opened this issue Jul 27, 2020 · 5 comments
Closed

Use Views to load asset/log details #14

mstenta opened this issue Jul 27, 2020 · 5 comments

Comments

@mstenta
Copy link
Owner

mstenta commented Jul 27, 2020

In #13 we identified some performance issues encountered as the number of plantings in a plan increases.

Currently, we are manually running a database query to get all plantings in the plan, and then running farm_asset_load() on each of them, as well as log_load() on each log. This results in a LOT of database queries, as well as lots of other unnecessary logic running (eg: all implementations of hook_entity_load() etc).

A much simpler approach would be to convert the whole page to a View, which would allow us to load all the information we need in a single database query, without any calls to farm_asset_load() or log_load(). This is probably the most impactful change we can make right now to help with server-side performance.

I think the steps to do this would be (roughly):

  1. Create a View that loads the information we need to build the crop plan.
  2. Convert the current theme functions to a Views display plugin so the View results can be rendered into the timeline display.
  3. Add the View to farm/plan/%
@mstenta
Copy link
Owner Author

mstenta commented Jul 27, 2020

Regarding:

  1. Create a View that loads the information we need to build the crop plan.

I tested this quickly, and found that there is more we need to do in order to be able to build this View.

Basically, we use a combination of hook_farm_plan_record_relationships() and hook_views_data_alter() to describe to Views the relationships between the farm_plan table, the farm_asset table, and our custom farm_crop_plan_plantings table.

However, it doesn't appear that the relationships we need are described yet. We need to be able to create a View of planting assets, and then add a "Relationship" to the plan via the farm_crop_plan_plantings table (joining farm_asset.id to farm_crop_plan_plantings.planting_id columns). I thought that relationship was covered, but I will need to look closer to see why it isn't available.

@mstenta
Copy link
Owner Author

mstenta commented Jul 27, 2020

Also curious: I'm not sure if the logic we have in farm_plan_views_data_alter() can properly handle database tables that contain multiple references, as we are doing in this module (we include planting_id, seeding_id, and transplanting_id in the same row).

@mstenta
Copy link
Owner Author

mstenta commented Aug 14, 2020

One other thought that came up based on feedback from Cora at Wolfe's Neck, which could be enabled with Views Bulk Operations:

We’re probably a ways away from this, but editing multiple entries at once would be super convenient. Not quite sure how this could work. For example, adding the same note to multiple logs. I guess that would maybe be checking multiple and then adding an observation log?

If all of the "rows" are Views results, it is conceivable that we could add a bulk action checkbox next to each one, and provide the same buttons at the top/bottom that we do on the Assets > Plantings page, for performing bulk operations on all plantings in a plan.

Might want a separate issue for that, but leaving it as a comment here for now.

@mstenta mstenta mentioned this issue Aug 14, 2020
@mstenta
Copy link
Owner Author

mstenta commented Aug 14, 2020

Might want a separate issue for that, but leaving it as a comment here for now.

Created a separate issue :-)

#25

@mstenta
Copy link
Owner Author

mstenta commented Jan 29, 2024

We are in the process of porting this module to farmOS v3, and moving it to https://www.drupal.org/project/farm_crop_plan, along with any open issues that are still relevant.

We can reassess needs in the new version and see if any of these same ideas still apply.

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

No branches or pull requests

1 participant