Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
arthur-zzz
noc
Commits
dacd73d0
Commit
dacd73d0
authored
May 06, 2019
by
Dmitry Volodin
Committed by
Aleksey Shirokih
May 06, 2019
Browse files
Move MongoCache index creation into ensure-indexes
parent
a3168c7a
Changes
2
Hide whitespace changes
Inline
Side-by-side
commands/ensure-indexes.py
View file @
dacd73d0
...
...
@@ -2,7 +2,7 @@
# ----------------------------------------------------------------------
# Ensure MongoDB indexes
# ----------------------------------------------------------------------
# Copyright (C) 2007-201
8
The NOC Project
# Copyright (C) 2007-201
9
The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
...
...
@@ -46,6 +46,8 @@ class Command(BaseCommand):
self
.
index_datastreams
()
# Index GridVCS
self
.
index_gridvcs
()
# Index mongo cache
self
.
index_cache
()
# @todo: Detect changes
self
.
print
(
"OK"
)
...
...
@@ -106,6 +108,13 @@ class Command(BaseCommand):
for
repo
in
REPOS
:
GridVCS
(
repo
).
ensure_collection
()
def
index_cache
(
self
):
from
noc.core.cache.base
import
cache
if
not
hasattr
(
cache
,
"ensure_indexes"
):
return
self
.
print
(
"[%s] Indexing cache"
%
cache
.
__class__
.
__name__
)
cache
.
ensure_indexes
()
if
__name__
==
"__main__"
:
Command
().
run
()
core/cache/mongo.py
View file @
dacd73d0
...
...
@@ -2,7 +2,7 @@
# ----------------------------------------------------------------------
# Mongo backend
# ----------------------------------------------------------------------
# Copyright (C) 2007-201
6
The NOC Project
# Copyright (C) 2007-201
9
The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
...
...
@@ -28,13 +28,17 @@ class MongoCache(BaseCache):
def
get_collection
(
cls
):
if
not
hasattr
(
cls
,
"_collection"
):
cls
.
_collection
=
get_db
()[
cls
.
collection_name
]
cls
.
ensure_indexes
()
return
cls
.
_collection
@
classmethod
def
ensure_indexes
(
cls
):
cls
.
_collection
.
ensure_index
(
cls
.
EXPIRES_FIELD
,
expireAfterSeconds
=
0
"""
Create all necessary indexes. Called by ensure-index
:return:
"""
cls
.
get_collection
().
create_index
(
cls
.
EXPIRES_FIELD
,
expireAfterSeconds
=
0
)
def
get
(
self
,
key
,
default
=
None
,
version
=
None
):
...
...
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