Commit dacd73d0 authored by Dmitry Volodin's avatar Dmitry Volodin Committed by Aleksey Shirokih
Browse files

Move MongoCache index creation into ensure-indexes

parent a3168c7a
......@@ -2,7 +2,7 @@
# ----------------------------------------------------------------------
# Ensure MongoDB indexes
# ----------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 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()
......@@ -2,7 +2,7 @@
# ----------------------------------------------------------------------
# Mongo backend
# ----------------------------------------------------------------------
# Copyright (C) 2007-2016 The NOC Project
# Copyright (C) 2007-2019 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):
......
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