some cleanup of unused relations code, introduced caching of related_names and props on model, set profiling

This commit is contained in:
collerek
2020-11-12 08:11:40 +01:00
parent 1242e5d600
commit e743286008
11 changed files with 95 additions and 466 deletions

View File

@ -1,32 +1,19 @@
from typing import Optional, TYPE_CHECKING, Tuple, Type
from typing import TYPE_CHECKING, Tuple, Type
from weakref import proxy
import ormar
from ormar.fields import BaseField
from ormar.fields.many_to_many import ManyToManyField
from ormar.relations import Relation
if TYPE_CHECKING: # pragma no cover
from ormar import Model
def register_missing_relation(
parent: "Model", child: "Model", child_name: str
) -> Optional[Relation]:
ormar.models.expand_reverse_relationships(child.__class__)
name = parent.resolve_relation_name(parent, child)
field = parent.Meta.model_fields[name]
parent._orm._add_relation(field)
parent_relation = parent._orm._get(child_name)
return parent_relation
def get_relations_sides_and_names(
to_field: Type[BaseField],
parent: "Model",
child: "Model",
child_name: str,
virtual: bool,
to_field: Type[BaseField],
parent: "Model",
child: "Model",
child_name: str,
virtual: bool,
) -> Tuple["Model", "Model", str, str]:
to_name = to_field.name
if issubclass(to_field, ManyToManyField):