Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e_zombie
noc
Commits
57a800b6
Commit
57a800b6
authored
Jun 22, 2022
by
Andrey Vertiprahov
Browse files
Merge branch 'issue-1822-clear-ObjectPath' into 'master'
Remove ObjectPath model See merge request
!6389
parents
7d42073c
7455a9de
Changes
1
Hide whitespace changes
Inline
Side-by-side
sa/models/objectpath.py
deleted
100644 → 0
View file @
7d42073c
# ---------------------------------------------------------------------
# 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
)
@
classmethod
def
refresh
(
cls
,
obj
):
ObjectPath
.
_get_collection
().
update
(
{
"_id"
:
obj
.
id
},
{
"$set"
:
{
"adm_path"
:
obj
.
administrative_domain
.
get_path
(),
"segment_path"
:
obj
.
segment
.
get_path
(),
"container_path"
:
obj
.
container
.
get_path
()
if
obj
.
container
else
[],
}
},
upsert
=
True
,
)
@
classmethod
@
cachetools
.
cachedmethod
(
operator
.
attrgetter
(
"_object_cache"
),
lock
=
lambda
_
:
id_lock
)
def
_get_path
(
cls
,
object_id
):
return
ObjectPath
.
objects
.
filter
(
object
=
object_id
).
first
()
@
classmethod
def
get_path
(
cls
,
object
):
if
hasattr
(
object
,
"id"
):
object
=
object
.
id
return
cls
.
_get_path
(
object
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment