Commit 57a800b6 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'issue-1822-clear-ObjectPath' into 'master'

Remove ObjectPath model

See merge request noc/noc!6389
parents 7d42073c 7455a9de
# ---------------------------------------------------------------------
# ObjectPath
# ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
from threading import Lock
import operator
# Third-party modules
from mongoengine.document import Document
from mongoengine.fields import ListField, ObjectIdField, IntField
import cachetools
id_lock = Lock()
class ObjectPath(Document):
meta = {"collection": "noc.cache.objectpaths", "strict": False, "auto_create_index": False}
# Object id
object = IntField(primary_key=True)
adm_path = ListField(IntField())
segment_path = ListField(ObjectIdField())
container_path = ListField(ObjectIdField())
_object_cache = cachetools.TTLCache(10000, ttl=300)
def refresh(cls, obj):
"$set": {
"adm_path": obj.administrative_domain.get_path(),
"segment_path": obj.segment.get_path(),
"container_path": obj.container.get_path() if obj.container else [],
@cachetools.cachedmethod(operator.attrgetter("_object_cache"), lock=lambda _: id_lock)
def _get_path(cls, object_id):
return ObjectPath.objects.filter(object=object_id).first()
def get_path(cls, object):
if hasattr(object, "id"):
object =
return cls._get_path(object)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment