mstenta / farm_crop_plan

Crop plan type and related features for farmOS. (ALPHA 3.x IN DEVELOPMENT)
https://drupal.org/project/farm_crop_plan
GNU General Public License v2.0
5 stars 1 forks source link

Use Views to load asset/log details #14

Closed mstenta closed 6 months ago

mstenta commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

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

Created a separate issue :-)

https://github.com/mstenta/farm_crop_plan/issues/25

mstenta commented 6 months ago

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.