@@ -306,21 +306,24 @@ def get_attributes(self,active=None,regexp=''):
306306 else :
307307 # Inactive attributes must be read from Database
308308 r = self .get_attribute_names (False )
309-
309+
310310 r = sorted (set (fn .tango .get_full_name (a ,fqdn = True ).lower ()
311311 for a in r ))
312312
313313 return sorted (fn .filtersmart (r ,regexp ) if regexp else r )
314314
315315 def get_attribute_names (self ,active = False ,regexp = '' ):
316+ t0 = fn .now ()
316317 if not active :
317- [ self . attributes [a [0 ].lower ()] for a
318- in self . Query ( 'select att_name from att_conf' ) ]
318+ attributes = [a [0 ].lower () for a in self . Query ( 'select att_name from att_conf' )]
319+ [ self . get_attr_id_type_table ( a ) for a in attributes if a not in self . attributes ]
319320 r = self .attributes .keys ()
320321 else :
321322 r = self .get_archived_attributes ()
322323
323- return sorted (fn .filtersmart (r ,regexp ) if regexp else r )
324+ r = sorted (fn .filtersmart (r ,regexp ) if regexp else r )
325+ self .debug ('get attribute names took %d ms' % (1e3 * (fn .now ()- t0 )))
326+ return r
324327
325328 @Cached (expire = 86400 )
326329 def get_data_types (self ):
@@ -329,7 +332,8 @@ def get_data_types(self):
329332
330333 def get_data_tables (self ):
331334 return sorted ('att_' + t for t in self .get_data_types ())
332-
335+
336+ @Cached (depth = 100 , expire = 60. )
333337 def get_attributes_by_table (self ,table = '' ,as_id = False ):
334338 if table :
335339 table = table .replace ('att_' ,'' )
@@ -389,31 +393,42 @@ def get_attribute_by_ID(self,ID):
389393
390394 def get_table_name (self ,attr ):
391395 return get_attr_id_type_table (attr )[- 1 ]
392-
396+
397+ @Cached (expire = 600 )
398+ def get_att_conf_table (self ):
399+ t0 = fn .now ()
400+ #types = self.Query('select att_conf_data_type_id, data_type from att_conf_data_type')
401+ #types = dict(types)
402+ q = "select att_name,att_conf_id,att_conf.att_conf_data_type_id,data_type "
403+ q += " from att_conf, att_conf_data_type where "
404+ q += "att_conf.att_conf_data_type_id = att_conf_data_type.att_conf_data_type_id"
405+ ids = self .Query (q )
406+ #self.debug(str((q, ids)))
407+ #ids = [list(t)+[types[t[-1]]] for t in ids]
408+ for i in ids :
409+ attr ,aid ,tid ,table = i
410+ self .attributes [attr ].id = aid
411+ self .attributes [attr ].tid = tid
412+ self .attributes [attr ].type = table
413+ self .attributes [attr ].table = 'att_' + table
414+ self .attributes [attr ].modes = {'MODE_E' :True }
415+
416+ return ids
417+
393418 @Cached (depth = 20000 ,expire = 3600 )
394419 def get_attr_id_type_table (self ,attr ):
395-
396- if fn .isNumber (attr ):
397- where = 'att_conf_id = %s' % attr
398- else :
399- where = "att_name like '%s'" % get_search_model (attr )
400-
401- q = "select att_name,att_conf_id,att_conf_data_type_id from att_conf" \
402- " where %s" % where
403- ids = self .Query (q )
404- self .debug (str ((q ,ids )))
405- if not ids :
406- return None ,None ,''
407-
408- attr ,aid ,tid = ids [0 ]
409- table = self .Query ("select data_type from att_conf_data_type " \
410- + "where att_conf_data_type_id = %s" % tid )[0 ][0 ]
411-
412- self .attributes [attr ].id = aid
413- self .attributes [attr ].type = table
414- self .attributes [attr ].table = 'att_' + table
415- self .attributes [attr ].modes = {'MODE_E' :True }
416- return aid ,tid ,'att_' + table
420+ if fn .isString (attr ):
421+ attr = fn .tango .get_full_name (attr ,True ).lower ()
422+
423+ if attr not in self .attributes :
424+ self .get_att_conf_table .cache .clear ()
425+ self .get_att_conf_table ()
426+
427+ if attr not in self .attributes :
428+ return None ,None ,''
429+
430+ attr = self .attributes [attr ]
431+ return attr .id , attr .type , attr .table
417432
418433 @Cached (depth = 1000 ,expire = 60. )
419434 def get_attribute_subscriber (self ,attribute ):
@@ -456,6 +471,13 @@ def is_attribute_archived(self,attribute,active=None,cached=True):
456471 for a in self .get_attributes ())
457472
458473 def start_servers (self ,host = '' ,restart = True ):
474+ """
475+ this method starts all servers processes
476+
477+ :param host:
478+ :param restart:
479+ :return:
480+ """
459481 import fandango .servers
460482 if not self .manager : self .get_manager ()
461483 astor = fandango .servers .Astor (self .manager )
@@ -479,6 +501,15 @@ def start_servers(self,host='',restart=True):
479501
480502 def start_devices (self ,regexp = '*' , force = False ,
481503 do_init = False , do_restart = False ):
504+ """
505+ this method starts servers if needed and launches command Start()
506+
507+ :param regexp:
508+ :param force:
509+ :param do_init:
510+ :param do_restart:
511+ :return:
512+ """
482513 #devs = fn.tango.get_class_devices('HdbEventSubscriber')
483514 devs = self .get_archivers ()
484515 if regexp :
@@ -683,7 +714,8 @@ def add_attributes(self,attributes,*args,**kwargs):
683714 traceback .print_exc ()
684715
685716 except Exception ,e :
686- print ('add_attribute(%s) failed!: %s' % (a ,traceback .print_exc ()))
717+ self .error ('add_attributes(%s) failed!: %s' % (
718+ attributes ,traceback .print_exc ()))
687719 return
688720
689721 def start_archiving (self ,attribute ,archiver ,period = 0 ,
0 commit comments