@@ -65,23 +65,27 @@ export default class Tag {
6565 return Tags ;
6666 }
6767
68- async getTagList ( offset : number = 0 , limit : number = 100 ) : Promise < TagData [ ] > {
68+ async getTagList (
69+ tagKeys : string [ ] = [ ] ,
70+ offset : number = 0 ,
71+ limit : number = 100 ,
72+ ) : Promise < TagData [ ] > {
6973 const { Tags, TotalCount } = await this . request ( {
7074 Action : 'DescribeTags' ,
7175 Limit : limit ,
7276 Offset : offset ,
77+ TagKeys : tagKeys ,
7378 } ) ;
7479 if ( TotalCount > limit ) {
75- return Tags . concat ( await this . getTagList ( offset + limit , limit ) ) ;
80+ return Tags . concat ( await this . getTagList ( tagKeys , offset + limit , limit ) ) ;
7681 }
7782
7883 return Tags ;
7984 }
8085
81- async isTagExist ( tag : TagData ) {
82- const tagList = await this . getTagList ( ) ;
86+ isTagExist ( tag : TagData , tagList : TagData [ ] = [ ] ) {
8387 const [ exist ] = tagList . filter (
84- ( item ) => item . TagKey === tag . TagKey && item . TagValue === tag . TagValue ,
88+ ( item ) => item . TagKey === tag . TagKey && String ( item . TagValue ) === String ( tag . TagValue ) ,
8589 ) ;
8690 return ! ! exist ;
8791 }
@@ -104,12 +108,15 @@ export default class Tag {
104108 ResourceRegion : this . region ,
105109 ResourcePrefix : resourcePrefix ,
106110 } ;
107- // if tag not exsit, create it
111+ if ( tags && tags . length > 0 ) {
112+ const tagKeys = tags . map ( ( item ) => item . TagKey ) ;
113+ const tagList = await this . getTagList ( tagKeys ) ;
108114
109- if ( tags ) {
110115 for ( let i = 0 ; i < tags . length ; i ++ ) {
111116 const currentTag = tags [ i ] ;
112- const tagExist = await this . isTagExist ( currentTag ) ;
117+ const tagExist = await this . isTagExist ( currentTag , tagList ) ;
118+
119+ // if tag not exsit, create it
113120 if ( ! tagExist ) {
114121 await this . createTag ( currentTag ) ;
115122 }
@@ -232,7 +239,7 @@ export default class Tag {
232239 const [ inputTag ] = tags . filter ( ( t ) => t . TagKey === item . TagKey ) ;
233240 const oldTagVal = item . TagValue ;
234241
235- if ( inputTag . TagValue !== oldTagVal ) {
242+ if ( String ( inputTag . TagValue ) !== String ( oldTagVal ) ) {
236243 attachTags . push ( inputTag ) ;
237244 } else {
238245 leftTags . push ( item ) ;
0 commit comments