ynput / ynput/ayon-python-api

Add support to provide regex filters on entity queries

Aperta
#139 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
16
Fork
15
Merge medio
1g 9h
PR unite (30g)
10

Descrizione

Looking into porting some of our code into AYON I noticed how much more complicated the new query functions look using the new API, for example, compare this new implementation of _get_representations on the workfile template: https://github.com/ynput/ayon-core/blob/d8e5734e57c19a740f0fa2c3f4a5984754f68431/client/ayon_core/pipeline/workfile/workfile_template_builder.py#L1436
To how it was in OP before:

def _get_representations(self, placeholder):
        """Prepared query of representations based on load options.

        This function is directly connected to options defined in
        'get_load_plugin_options'.

        Note:
            This returns all representation documents from all versions of
                matching subset. To filter for last version use
                '_reduce_last_version_repre_docs'.

        Args:
            placeholder (PlaceholderItem): Item which should be populated.

        Returns:
            List[Dict[str, Any]]: Representation documents matching filters
                from placeholder data.
        """

        project_name = self.builder.project_name
        current_asset_doc = self.builder.current_asset_doc
        linked_asset_docs = self.builder.linked_asset_docs

        builder_type = placeholder.data["builder_type"]
        if builder_type == "context_asset":
            context_filters = {
                "asset": [current_asset_doc["name"]],
                "subset": [re.compile(placeholder.data["subset"])],
                "hierarchy": [re.compile(placeholder.data["hierarchy"])],
                "representation": [placeholder.data["representation"]],
                "family": [placeholder.data["family"]]
            }

        elif builder_type == "linked_asset":
            asset_regex = re.compile(placeholder.data["asset"])
            linked_asset_names = []
            for asset_doc in linked_asset_docs:
                asset_name = asset_doc["name"]
                if asset_regex.match(asset_name):
                    linked_asset_names.append(asset_name)

            context_filters = {
                "asset": linked_asset_names,
                "subset": [re.compile(placeholder.data["subset"])],
                "hierarchy": [re.compile(placeholder.data["hierarchy"])],
                "representation": [placeholder.data["representation"]],
                "family": [placeholder.data["family"]],
            }

        else:
            context_filters = {
                "asset": [re.compile(placeholder.data["asset"])],
                "subset": [re.compile(placeholder.data["subset"])],
                "hierarchy": [re.compile(placeholder.data["hierarchy"])],
                "representation": [placeholder.data["representation"]],
                "family": [placeholder.data["family"]]
            }

        return list(get_representations(
            project_name,
            context_filters=context_filters
        ))

My worry is not only the fact that the API doesn't provide that same support but the fact that not having that is now forcing the user to provide much more expensive implementations to get to the same result. In the new code you are now having to query ALL products and then filter them rather than doing it directly on the query

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia tracciando le nuove funzioni di query delle entità e l’entry point get_representations, quindi confronta il loro comportamento con _get_representations in workfile_template_builder.py dell’esempio AYON Core collegato. Determina come devono essere passati i filtri regex tramite l’API e verifica che il filtraggio avvenga durante la query anziché dopo aver recuperato tutte le entità.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
api
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.