瀏覽代碼

HUE-8608 [useradmin] Add config check on number of documents

Ying Chen 7 年之前
父節點
當前提交
1b4a565
共有 2 個文件被更改,包括 17 次插入0 次删除
  1. 14 0
      desktop/core/src/desktop/conf.py
  2. 3 0
      desktop/core/src/desktop/settings.py

+ 14 - 0
desktop/core/src/desktop/conf.py

@@ -1776,9 +1776,23 @@ def config_validator(user):
 
   Called by core check_config() view.
   """
+  from beeswax.models import Session
   from desktop.lib import i18n
+  from desktop.models import Document2 # Avoid cyclic loop
+  from desktop.settings import DOCUMENT2_MAX_ENTRIES # Avoid cyclic loop
 
   res = []
+
+  doc2_count = Document2.objects.filter(is_history=True).count()
+  if doc2_count > DOCUMENT2_MAX_ENTRIES:
+    res.append(('DOCUMENT2_CLEANUP_WARNING', unicode(_('Desktop Document2 has more than %d entries: %d, '
+                'please run "hue desktop_document_cleanup --cm-managed" to remove old entries' % (DOCUMENT2_MAX_ENTRIES, doc2_count)))))
+
+  session_count = Session.objects.filter(status_code__gte=-10000).count()
+  if session_count > DOCUMENT2_MAX_ENTRIES:
+    res.append(('SESSION_CLEANUP_WARNING', unicode(_('Desktop Session has more than %d entries: %d, '
+                'please run "hue desktop_document_cleanup --cm-managed" to remove old entries' % (DOCUMENT2_MAX_ENTRIES, session_count)))))
+
   if not get_secret_key():
     res.append((SECRET_KEY, unicode(_("Secret key should be configured as a random string. All sessions will be lost on restart"))))
 

+ 3 - 0
desktop/core/src/desktop/settings.py

@@ -579,6 +579,9 @@ if not desktop.conf.DATABASE_LOGGING.get():
 # For performance reasons and to avoid searching in huge fields, we also truncate to a max length
 DOCUMENT2_SEARCH_MAX_LENGTH = 2000
 
+# To avoid performace issue, config check will display warning when Document2 over this size
+DOCUMENT2_MAX_ENTRIES = 100000
+
 DEBUG_TOOLBAR_PATCH_SETTINGS = False
 
 def show_toolbar(request):