platform icon indicating copy to clipboard operation
platform copied to clipboard

Reduce the amount of flattening and reconstituting of hierarchy trees

Open paul-butcher opened this issue 3 years ago • 1 comments

In https://github.com/wellcomecollection/catalogue-pipeline/blob/main/pipeline/relation_embedder/relation_embedder/src/main/scala/weco/pipeline/relation_embedder/RelationsService.scala#L42-L50 getRelationTree fetches each ancestor, based on individual collectionPath fragments. This becomes a flat list.

In https://github.com/wellcomecollection/catalogue-api/blob/3954e6f625a4c6af5cea2e490257bc61e81feedb/common/display/src/main/scala/weco/catalogue/display_model/models/DisplayWork.scala#L198-L208 A flat list of ancestors is assumed to mean "parent, grandparent, great-grandparent" etc. and that foldLeft turns the flat list into a hierarchy.

In https://github.com/wellcomecollection/wellcomecollection.org/blob/8b9c14402acf31f6eac98701f11a355aa61a6c16/catalogue/webapp/components/ArchiveTree/ArchiveTree.tsx a tree of ancestors is fetched from the API, flattened (getArchiveAncestorArray) and then turned into a tree (createBasicTree).

I find this a bit confusing, and it caused some difficulty when updating partOf to contain multiple relations that a Work could directly be part of (https://github.com/wellcomecollection/catalogue-api/pull/360).

paul-butcher avatar Mar 01 '22 16:03 paul-butcher