Browse Source

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

Ying Chen 7 years ago
parent
commit
1b4a565
2 changed files with 17 additions and 0 deletions
  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.
   Called by core check_config() view.
   """
   """
+  from beeswax.models import Session
   from desktop.lib import i18n
   from desktop.lib import i18n
+  from desktop.models import Document2 # Avoid cyclic loop
+  from desktop.settings import DOCUMENT2_MAX_ENTRIES # Avoid cyclic loop
 
 
   res = []
   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():
   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"))))
     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
 # For performance reasons and to avoid searching in huge fields, we also truncate to a max length
 DOCUMENT2_SEARCH_MAX_LENGTH = 2000
 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
 DEBUG_TOOLBAR_PATCH_SETTINGS = False
 
 
 def show_toolbar(request):
 def show_toolbar(request):