mirror of
https://github.com/clearml/clearml-server
synced 2025-03-16 10:29:46 +00:00
Optimize MongoDB indices usage for large dbs
This commit is contained in:
parent
a1956cdd83
commit
ee9f45ea61
@ -186,7 +186,7 @@ class ModelBLL:
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"$match": {
|
"$match": {
|
||||||
"company": {"$in": [None, "", company]},
|
"company": {"$in": ["", company]},
|
||||||
"_id": {"$in": model_ids},
|
"_id": {"$in": model_ids},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -43,8 +43,8 @@ class _TagsCache:
|
|||||||
query &= GetMixin.get_list_field_query(name, vals)
|
query &= GetMixin.get_list_field_query(name, vals)
|
||||||
if project:
|
if project:
|
||||||
query &= Q(project__in=project_ids_with_children([project]))
|
query &= Q(project__in=project_ids_with_children([project]))
|
||||||
else:
|
# else:
|
||||||
query &= Q(system_tags__nin=[EntityVisibility.hidden.value])
|
# query &= Q(system_tags__nin=[EntityVisibility.hidden.value])
|
||||||
|
|
||||||
return self.db_cls.objects(query).distinct(field)
|
return self.db_cls.objects(query).distinct(field)
|
||||||
|
|
||||||
|
@ -1015,8 +1015,8 @@ class ProjectBLL:
|
|||||||
if include_subprojects:
|
if include_subprojects:
|
||||||
projects = _ids_with_children(projects)
|
projects = _ids_with_children(projects)
|
||||||
query &= Q(project__in=projects)
|
query &= Q(project__in=projects)
|
||||||
else:
|
# else:
|
||||||
query &= Q(system_tags__nin=[EntityVisibility.hidden.value])
|
# query &= Q(system_tags__nin=[EntityVisibility.hidden.value])
|
||||||
|
|
||||||
if state == EntityVisibility.archived:
|
if state == EntityVisibility.archived:
|
||||||
query &= Q(system_tags__in=[EntityVisibility.archived.value])
|
query &= Q(system_tags__in=[EntityVisibility.archived.value])
|
||||||
@ -1101,7 +1101,7 @@ class ProjectBLL:
|
|||||||
project_field: str = "project",
|
project_field: str = "project",
|
||||||
):
|
):
|
||||||
conditions = {
|
conditions = {
|
||||||
"company": {"$in": [None, "", company]},
|
"company": {"$in": ["", company]},
|
||||||
project_field: {"$in": project_ids},
|
project_field: {"$in": project_ids},
|
||||||
}
|
}
|
||||||
if users:
|
if users:
|
||||||
|
@ -47,7 +47,7 @@ class ProjectQueries:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_company_constraint(company_id: str, allow_public: bool = True) -> dict:
|
def _get_company_constraint(company_id: str, allow_public: bool = True) -> dict:
|
||||||
if allow_public:
|
if allow_public:
|
||||||
return {"company": {"$in": [None, "", company_id]}}
|
return {"company": {"$in": ["", company_id]}}
|
||||||
|
|
||||||
return {"company": company_id}
|
return {"company": company_id}
|
||||||
|
|
||||||
|
@ -525,7 +525,7 @@ class QueueBLL(object):
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"$match": {
|
"$match": {
|
||||||
"company": {"$in": [None, "", company]},
|
"company": {"$in": ["", company]},
|
||||||
"_id": queue_id,
|
"_id": queue_id,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -193,7 +193,7 @@ class HyperParams:
|
|||||||
pipeline = [
|
pipeline = [
|
||||||
{
|
{
|
||||||
"$match": {
|
"$match": {
|
||||||
"company": {"$in": [None, "", company_id]},
|
"company": {"$in": ["", company_id]},
|
||||||
"_id": {"$in": task_ids},
|
"_id": {"$in": task_ids},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1394,7 +1394,7 @@ class DbModelMixin(GetMixin, ProperDictMixin, UpdateMixin):
|
|||||||
else:
|
else:
|
||||||
items = list(
|
items = list(
|
||||||
cls.objects(
|
cls.objects(
|
||||||
id__in=ids, company__in=(None, ""), company_origin=company_id
|
id__in=ids, company="", company_origin=company_id
|
||||||
).only("id")
|
).only("id")
|
||||||
)
|
)
|
||||||
update: dict = dict(set__company=company_id, unset__company_origin=1)
|
update: dict = dict(set__company=company_id, unset__company_origin=1)
|
||||||
|
@ -37,10 +37,18 @@ class Model(AttributedDocument):
|
|||||||
"project",
|
"project",
|
||||||
"task",
|
"task",
|
||||||
"last_update",
|
"last_update",
|
||||||
("company", "framework"),
|
("company", "last_update"),
|
||||||
("company", "name"),
|
("company", "name"),
|
||||||
("company", "user"),
|
|
||||||
("company", "uri"),
|
("company", "uri"),
|
||||||
|
# distinct queries support
|
||||||
|
("company", "tags"),
|
||||||
|
("company", "system_tags"),
|
||||||
|
("company", "project", "tags"),
|
||||||
|
("company", "project", "system_tags"),
|
||||||
|
("company", "user"),
|
||||||
|
("company", "project", "user"),
|
||||||
|
("company", "framework"),
|
||||||
|
("company", "project", "framework"),
|
||||||
{
|
{
|
||||||
"name": "%s.model.main_text_index" % Database.backend,
|
"name": "%s.model.main_text_index" % Database.backend,
|
||||||
"fields": ["$name", "$id", "$comment", "$parent", "$task", "$project"],
|
"fields": ["$name", "$id", "$comment", "$parent", "$task", "$project"],
|
||||||
|
@ -183,9 +183,8 @@ class Task(AttributedDocument):
|
|||||||
"status_changed",
|
"status_changed",
|
||||||
"models.input.model",
|
"models.input.model",
|
||||||
("company", "name"),
|
("company", "name"),
|
||||||
("company", "user"),
|
|
||||||
("company", "status", "type"),
|
("company", "status", "type"),
|
||||||
("company", "system_tags", "last_update"),
|
("company", "last_update", "system_tags"),
|
||||||
("company", "type", "system_tags", "status"),
|
("company", "type", "system_tags", "status"),
|
||||||
("company", "project", "type", "system_tags", "status"),
|
("company", "project", "type", "system_tags", "status"),
|
||||||
("status", "last_update"), # for maintenance tasks
|
("status", "last_update"), # for maintenance tasks
|
||||||
@ -193,6 +192,17 @@ class Task(AttributedDocument):
|
|||||||
"fields": ["company", "project"],
|
"fields": ["company", "project"],
|
||||||
"collation": AttributedDocument._numeric_locale,
|
"collation": AttributedDocument._numeric_locale,
|
||||||
},
|
},
|
||||||
|
# distinct queries support
|
||||||
|
("company", "tags"),
|
||||||
|
("company", "system_tags"),
|
||||||
|
("company", "project", "tags"),
|
||||||
|
("company", "project", "system_tags"),
|
||||||
|
("company", "user"),
|
||||||
|
("company", "project", "user"),
|
||||||
|
("company", "parent"),
|
||||||
|
("company", "project", "parent"),
|
||||||
|
("company", "type"),
|
||||||
|
("company", "project", "type"),
|
||||||
{
|
{
|
||||||
"name": "%s.task.main_text_index" % Database.backend,
|
"name": "%s.task.main_text_index" % Database.backend,
|
||||||
"fields": [
|
"fields": [
|
||||||
|
@ -121,8 +121,8 @@ def init_cls_from_base(cls, instance):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_company_or_none_constraint(company=None):
|
def get_company_or_none_constraint(company=""):
|
||||||
return Q(company__in=(company, None, "")) | Q(company__exists=False)
|
return Q(company__in=list({company, ""}))
|
||||||
|
|
||||||
|
|
||||||
def field_does_not_exist(field: str, empty_value=None, is_list=False) -> Q:
|
def field_does_not_exist(field: str, empty_value=None, is_list=False) -> Q:
|
||||||
|
@ -188,7 +188,12 @@ def get_all(call: APICall, company_id, _):
|
|||||||
def get_frameworks(call: APICall, company_id, request: GetFrameworksRequest):
|
def get_frameworks(call: APICall, company_id, request: GetFrameworksRequest):
|
||||||
call.result.data = {
|
call.result.data = {
|
||||||
"frameworks": sorted(
|
"frameworks": sorted(
|
||||||
project_bll.get_model_frameworks(company_id, project_ids=request.projects)
|
filter(
|
||||||
|
None,
|
||||||
|
project_bll.get_model_frameworks(
|
||||||
|
company_id, project_ids=request.projects
|
||||||
|
),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -590,7 +595,10 @@ def _delete_model_events(
|
|||||||
)
|
)
|
||||||
|
|
||||||
event_urls = delete_task_events_and_collect_urls(
|
event_urls = delete_task_events_and_collect_urls(
|
||||||
company=company_id, task_ids=model_ids, model=True, wait_for_delete=sync_delete
|
company=company_id,
|
||||||
|
task_ids=model_ids,
|
||||||
|
model=True,
|
||||||
|
wait_for_delete=sync_delete,
|
||||||
)
|
)
|
||||||
if event_urls:
|
if event_urls:
|
||||||
schedule_for_delete(
|
schedule_for_delete(
|
||||||
@ -601,7 +609,9 @@ def _delete_model_events(
|
|||||||
can_delete_folders=False,
|
can_delete_folders=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
event_bll.delete_task_events(company_id, model_ids, model=True, wait_for_delete=sync_delete)
|
event_bll.delete_task_events(
|
||||||
|
company_id, model_ids, model=True, wait_for_delete=sync_delete
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@endpoint("models.delete", request_data_model=DeleteModelRequest)
|
@endpoint("models.delete", request_data_model=DeleteModelRequest)
|
||||||
|
Loading…
Reference in New Issue
Block a user