How to save entire term lineage I need to save term lineage in Drupal 8, not only the deepest term. I know there are modules like Hierarchical select, Simple hierarchical select or Client-side hierarchical select but these are not for Drupal 8, or not solves "save term lineage" functionality.

I need to get my "nodes" visible on both child term and parent term pages too. I know, I can use the "Content: Has taxonomy term ID (with depth)" (under contextual filters) functionality in "views", but it slows the database queries very much. Or maybe I'm doing something wrong.

Is there some reasonable solution?

Thank you!

EDIT: The hierarchy is very simple. Only two-tiered: Country / City.

Can someone help me to re-save my nodes with "lineage" structure? For example, using the TermStorage functions listed below?
Depends on your understanding of reasonable. Until hierarchical select or similar modules become available you could save the parent terms programmatically on node save - the code probably wouldn't exceed 30 lines or so, especially when you don't have many taxonomy fields where you want to do this. 

You can access a term's parents with the following code utilizing TermStorage:

$parents = \Drupal::entityTypeManager()-&gt;getStorage('taxonomy_term')-&gt;loadParents($termId);


Then you only need to go recursively through the tree and grab all parents (if your terms can have more than one), get their ids and set them in the node you want to save.