summaryrefslogtreecommitdiffstats
path: root/funcweb
diff options
context:
space:
mode:
authormakkalot <makkalot@gmail.com>2008-07-02 16:20:55 +0300
committermakkalot <makkalot@gmail.com>2008-07-02 16:20:55 +0300
commit6f5c641010029972c6e3d3bc574a7ce26d3b0d10 (patch)
tree1997fae1ef3d2543c1c9950e5d254e798cdb89c4 /funcweb
parent32096347a68f1c68e89299398c4a4e940ea5a9dd (diff)
downloadfunc-6f5c641010029972c6e3d3bc574a7ce26d3b0d10.tar.gz
func-6f5c641010029972c6e3d3bc574a7ce26d3b0d10.tar.xz
func-6f5c641010029972c6e3d3bc574a7ce26d3b0d10.zip
adding some simple cache mechanism for fc = Overlord(minion) thing , we do that for every request which wasnt efficient, also annoyying :) With that patch the xmlrpc calls will be reduced which is good.
Diffstat (limited to 'funcweb')
-rw-r--r--funcweb/funcweb/controllers.py153
1 files changed, 119 insertions, 34 deletions
diff --git a/funcweb/funcweb/controllers.py b/funcweb/funcweb/controllers.py
index 298547e..d19dace 100644
--- a/funcweb/funcweb/controllers.py
+++ b/funcweb/funcweb/controllers.py
@@ -28,14 +28,33 @@ def validate_decorator_updater(validator_value=None):
class Root(controllers.RootController):
-
+ #preventing the everytime polling and getting
+ #func = Overlord("name") thing
+ func_cache={
+ 'fc_object':None,#the fc = Overlord() thing,
+ 'glob':None,
+ 'minion_name':None,
+ 'module_name':None,
+ 'modules':None,
+ 'minions':None,
+ 'methods':None
+ }
#will be reused for widget validation
@expose(template="funcweb.templates.minions")
@identity.require(identity.not_anonymous())
def minions(self, glob='*'):
""" Return a list of our minions that match a given glob """
- return dict(minions=Minions(glob).get_all_hosts())
+ #make the cache thing
+ if self.func_cache['glob'] == glob:
+ minions = self.func_cache['minions']
+ else:
+ #we dont have it it is for first time so lets pull it
+ minions=Minions(glob).get_all_hosts()
+ self.func_cache['glob']=glob
+ self.func_cache['minions']=minions
+
+ return dict(minions=minions)
index = minions # start with our minion view, for now
@@ -49,39 +68,70 @@ class Root(controllers.RootController):
methods. If a method is supplied, it will display a method execution
form.
"""
- fc = Overlord(name)
- if not module: # list all modules
- #just list those who have get_method_args
- modules = fc.system.list_modules()
- display_modules = []
- #FIXME slow really i know !
- for module in modules.itervalues():
- for mod in module:
- #if it is not empty
- if getattr(fc,mod).get_method_args()[name]:
- display_modules.append(mod)
+ #if we have it in the cache
+ if self.func_cache['minion_name'] == name:
+ fc = self.func_cache['fc_object']
+ else:
+ fc = Overlord(name)
+ self.func_cache['fc_object']=fc
+ self.func_cache['minion_name']=name
+ #reset the children :)
+ self.func_cache['module_name']=None
+ self.func_cache['modules']=None
+ self.func_cache['methods']=None
+
+ #should also reset the other fields or not ?
+
+
+ if not module:
+ if not self.func_cache['modules']:
+ modules = fc.system.list_modules()
+ display_modules = []
+
+ for module in modules.itervalues():
+ for mod in module:
+ #if it is not empty
+ if getattr(fc,mod).get_method_args()[name]:
+ display_modules.append(mod)
+
+ #put it into the cache to make that slow thing faster
+ self.func_cache['modules']=display_modules
+
+ else:
+ #print "Im in the cache"
+ #just list those who have get_method_args
+ display_modules = self.func_cache['modules']
+
modules = {}
modules[name]=display_modules
return dict(modules=modules)
else: # a module is specified
- if method: # minion.module.method specified; bring up execution form
- return dict(minion=name, module=module, method=method,
- tg_template="funcweb.templates.method")
- else: # return a list of methods for specified module
-
- #display the list only that is registered with register_method template !
- registered_methods=getattr(fc,module).get_method_args()[name].keys()
- modules = getattr(fc, module).list_methods()
- for mods in modules.itervalues():
- from copy import copy
- cp_mods = copy(mods)
- for m in cp_mods:
- if not m in registered_methods:
- mods.remove(m)
- print modules
+ if not method: # return a list of methods for specified module
+ #first check if we have it into the cache
+ if self.func_cache['module_name'] == module and self.func_cache['methods']:
+ modules = self.func_cache['methods']
+ #print "Im in the cache"
+
+ else:
+ self.func_cache['module_name']= module
+ #display the list only that is registered with register_method template !
+ registered_methods=getattr(fc,module).get_method_args()[name].keys()
+ modules = getattr(fc, module).list_methods()
+ for mods in modules.itervalues():
+ from copy import copy
+ cp_mods = copy(mods)
+ for m in cp_mods:
+ if not m in registered_methods:
+ mods.remove(m)
+
+ #store into cache if we get it again
+ self.func_cache['methods'] = modules
+ #display em
return dict(modules=modules, module=module,
tg_template="funcweb.templates.module")
+ else:
+ return "Wrong place :)"
@expose(template="funcweb.templates.method_args")
@@ -89,11 +139,22 @@ class Root(controllers.RootController):
def method_display(self,minion=None,module=None,method=None):
global global_form
- fc = Overlord(minion)
+ if self.func_cache['minion_name'] == minion:
+ fc = self.func_cache['fc_object']
+ else:
+ fc = Overlord(minion)
+ self.func_cache['fc_object']=fc
+ self.func_cache['minion_name']=minion
+ #reset the children :)
+ self.func_cache['module_name']=module
+ self.func_cache['modules']=None
+ self.func_cache['methods']=None
+
+ #get the method args
method_args = getattr(fc,module).get_method_args()
if not method_args.values():
- print "Not registered method here"
+ #print "Not registered method here"
return dict(minion_form = None,minion=minion,module=module,method=method)
minion_arguments = method_args[minion][method]['args']
@@ -177,12 +238,26 @@ class Root(controllers.RootController):
if kw.has_key('minion') and kw.has_key('module') and kw.has_key('method'):
#assign them because we need the rest so dont control everytime
#and dont make lookup everytime ...
+ #the del statements above are important dont remove them :)
minion = kw['minion']
+ del kw['minion']
module = kw['module']
+ del kw['module']
method = kw['method']
-
- #everytime we do that should be a clever way for that ???
- fc = Overlord(minion)
+ del kw['method']
+
+ if self.func_cache['minion_name'] == minion:
+ fc = self.func_cache['fc_object']
+ else:
+ fc = Overlord(minion)
+ self.func_cache['fc_object']=fc
+ self.func_cache['minion_name']=minion
+ #reset the children :)
+ self.func_cache['module_name']=module
+ self.func_cache['modules']=None
+ self.func_cache['methods']=None
+
+
#get again the method args to get their order :
arguments=getattr(fc,module).get_method_args()
#so we know the order just allocate and put them there
@@ -208,7 +283,17 @@ class Root(controllers.RootController):
arguments so they provide only some information,executed
by pressing only the link !
"""
- fc = Overlord(minion)
+ if self.func_cache['minion_name'] == minion:
+ fc = self.func_cache['fc_object']
+ else:
+ fc = Overlord(minion)
+ self.func_cache['fc_object']=fc
+ self.func_cache['minion_name']=minion
+ #reset the children :)
+ self.func_cache['module_name']=module
+ self.func_cache['modules']=None
+ self.func_cache['methods']=None
+
result = getattr(getattr(fc,module),method)()
return str(result)