11process . env . NODE_TLS_REJECT_UNAUTHORIZED = "0" ;
22
3+ import pMemoize from 'p-memoize' ;
4+
35export type MonitorResponse = {
46 id : string ,
57 indexId : string ,
@@ -10,6 +12,12 @@ export class OpendistroClient {
1012 private readonly password : string ;
1113 private readonly dashboardPrivateUrl : string ;
1214
15+ // Cache TTL: 1 day in milliseconds (Step 1)
16+ private static readonly INDEX_PATTERN_CACHE_TTL = 24 * 60 * 60 * 1000 ;
17+
18+ // Memoized function for index pattern lookup (created per-instance, Step 3)
19+ private readonly getIndexPatternMemoized : ( indexName : string ) => Promise < string > ;
20+
1321 constructor (
1422 dashboardPrivateUrl : string ,
1523 username : string ,
@@ -18,6 +26,12 @@ export class OpendistroClient {
1826 this . dashboardPrivateUrl = dashboardPrivateUrl ;
1927 this . username = username ;
2028 this . password = password ;
29+
30+ // Create memoized version of the helper (Step 3)
31+ this . getIndexPatternMemoized = pMemoize (
32+ this . _getIndexPatternIdByIndexName . bind ( this ) ,
33+ { maxAge : OpendistroClient . INDEX_PATTERN_CACHE_TTL }
34+ ) ;
2135 }
2236
2337
@@ -51,6 +65,11 @@ export class OpendistroClient {
5165 }
5266
5367 public async getIndexPatternIdByIndexName ( indexName : string ) : Promise < string >
68+ {
69+ return this . getIndexPatternMemoized ( indexName ) ;
70+ }
71+
72+ private async _getIndexPatternIdByIndexName ( indexName : string ) : Promise < string >
5473 {
5574 const base = indexName . split ( '-' ) ;
5675 if ( base [ base . length - 1 ] === '*' ) {
0 commit comments