@@ -27,17 +27,6 @@ def __init__(
2727 self .token = token
2828 self .timeout = 30
2929
30- def _get_table_id_by_name (self , table_name ):
31- if self ._cache_table_name_id_map :
32- return self ._cache_table_name_id_map .get (table_name )
33- tables = self .list_tables ()
34- table_name_id_map = {t .get ('name' ): t .get ('_id' ) for t in tables }
35- self ._cache_table_name_id_map = table_name_id_map
36- return table_name_id_map .get (table_name ) or table_name
37-
38- def _clean_table_cache (self ):
39- self ._cache_table_name_id_map = {}
40-
4130 def _metadata_server_url (self ):
4231 return self .api_gateway_url + '/api/v2/dtables/' + self .dtable_uuid + '/metadata/'
4332
@@ -122,7 +111,6 @@ def add_table(self, table_name, lang='en', columns=[]):
122111 if columns :
123112 json_data ['columns' ] = columns
124113 response = requests .post (url , json = json_data , headers = self .headers , timeout = self .timeout )
125- self ._clean_table_cache ()
126114 return parse_response (response )
127115
128116 def rename_table (self , table_name , new_table_name ):
@@ -132,7 +120,6 @@ def rename_table(self, table_name, new_table_name):
132120 'new_table_name' : new_table_name
133121 }
134122 response = requests .put (url , json = json_data , headers = self .headers , timeout = self .timeout )
135- self ._clean_table_cache ()
136123 return parse_response (response )
137124
138125 def delete_table (self , table_name ):
@@ -141,7 +128,6 @@ def delete_table(self, table_name):
141128 'table_name' : table_name ,
142129 }
143130 response = requests .delete (url , json = json_data , headers = self .headers , timeout = self .timeout )
144- self ._clean_table_cache ()
145131 return parse_response (response )
146132
147133 def list_views (self , table_name ):
@@ -419,14 +405,16 @@ def add_link(self, link_id, table_name, other_table_name, row_id, other_row_id):
419405 :param other_row_id: str
420406 """
421407 url = self ._row_link_server_url ()
422- table_id = self ._get_table_id_by_name (table_name )
423- other_table_id = self ._get_table_id_by_name (other_table_name )
424408 json_data = {
425409 'link_id' : link_id ,
426- 'table_id ' : table_id ,
427- 'other_table_id ' : other_table_id ,
410+ 'table_name ' : table_name ,
411+ 'other_table_name ' : other_table_name ,
428412 'other_rows_ids_map' : {row_id : [other_row_id , ]}
429413 }
414+ if like_table_id (table_name ):
415+ json_data ['table_id' ] = table_name
416+ if like_table_id (other_table_name ):
417+ json_data ['other_table_id' ] = other_table_name
430418
431419 response = requests .post (url , json = json_data , headers = self .headers , timeout = self .timeout )
432420 return parse_response (response )
@@ -441,15 +429,16 @@ def remove_link(self, link_id, table_name, other_table_name, row_id, other_row_i
441429 :param other_row_id: str
442430 """
443431 url = self ._row_link_server_url ()
444- table_id = self ._get_table_id_by_name (table_name )
445- other_table_id = self ._get_table_id_by_name (other_table_name )
446432 json_data = {
447433 'link_id' : link_id ,
448- 'table_id ' : table_id ,
449- 'other_table_id ' : other_table_id ,
434+ 'table_name ' : table_name ,
435+ 'other_table_name ' : other_table_name ,
450436 'other_rows_ids_map' : {row_id : [other_row_id , ]}
451437 }
452-
438+ if like_table_id (table_name ):
439+ json_data ['table_id' ] = table_name
440+ if like_table_id (other_table_name ):
441+ json_data ['other_table_id' ] = other_table_name
453442 response = requests .delete (url , json = json_data , headers = self .headers , timeout = self .timeout )
454443 return parse_response (response )
455444
@@ -465,15 +454,17 @@ def update_link(self, link_id, table_name, other_table_name, row_id, other_rows_
465454 if not isinstance (other_rows_ids , list ):
466455 raise ValueError ('params other_rows_ids requires type list' )
467456 url = self ._row_link_server_url ()
468- table_id = self ._get_table_id_by_name (table_name )
469- other_table_id = self ._get_table_id_by_name (other_table_name )
470457 json_data = {
471458 'link_id' : link_id ,
472- 'table_id ' : table_id ,
473- 'other_table_id ' : other_table_id ,
459+ 'table_name ' : table_name ,
460+ 'other_table_name ' : other_table_name ,
474461 'row_id_list' : [row_id , ],
475462 'other_rows_ids_map' : {row_id : other_rows_ids }
476463 }
464+ if like_table_id (table_name ):
465+ json_data ['table_id' ] = table_name
466+ if like_table_id (other_table_name ):
467+ json_data ['other_table_id' ] = other_table_name
477468
478469 response = requests .put (url , json = json_data , headers = self .headers , timeout = self .timeout )
479470 return parse_response (response )
@@ -488,16 +479,17 @@ def batch_update_links(self, link_id, table_name, other_table_name, row_id_list,
488479 :param other_rows_ids_map: dict
489480 """
490481 url = self ._batch_update_row_link_server_url ()
491-
492- table_id = self ._get_table_id_by_name (table_name )
493- other_table_id = self ._get_table_id_by_name (other_table_name )
494482 json_data = {
495483 'link_id' : link_id ,
496- 'table_id ' : table_id ,
497- 'other_table_id ' : other_table_id ,
484+ 'table_name ' : table_name ,
485+ 'other_table_name ' : other_table_name ,
498486 'row_id_list' : row_id_list ,
499487 'other_rows_ids_map' : other_rows_ids_map ,
500488 }
489+ if like_table_id (table_name ):
490+ json_data ['table_id' ] = table_name
491+ if like_table_id (other_table_name ):
492+ json_data ['other_table_id' ] = other_table_name
501493 response = requests .put (url , json = json_data , headers = self .headers , timeout = self .timeout )
502494 return parse_response (response )
503495
0 commit comments