@@ -41,20 +41,22 @@ const getUserData = (id) =>
4141 } ) ;
4242 } ) ;
4343
44- const cacheTryGet = async ( _id , params , func ) => {
44+ const cacheTryGet = async ( _id , params , func , cacheKey = func . name ) => {
4545 const userData : any = await getUserData ( _id ) ;
4646 const id = ( userData . data ?. user || userData . data ?. user_result ) ?. result ?. rest_id ;
4747 if ( id === undefined ) {
4848 cache . set ( `twitter-userdata-${ _id } ` , '' , config . cache . contentExpire ) ;
4949 throw new InvalidParameterError ( 'User not found' ) ;
5050 }
51- const funcName = func . name ;
5251 const paramsString = JSON . stringify ( params ) ;
53- return cache . tryGet ( `twitter:${ id } :${ funcName } :${ paramsString } ` , ( ) => func ( id , params ) , config . cache . routeExpire , false ) ;
52+ return cache . tryGet ( `twitter:${ id } :${ cacheKey } :${ paramsString } ` , ( ) => func ( id , params ) , config . cache . routeExpire , false ) ;
5453} ;
5554
5655const getUserTweets = ( id : string , params ?: Record < string , any > ) =>
57- cacheTryGet ( id , params , async ( id , params = { } ) =>
56+ cacheTryGet (
57+ id ,
58+ params ,
59+ async ( id , params = { } ) =>
5860 gatherLegacyFromData (
5961 await paginationTweets ( 'UserTweets' , id , {
6062 ...params ,
@@ -64,11 +66,15 @@ const getUserTweets = (id: string, params?: Record<string, any>) =>
6466 withVoice : true ,
6567 withV2Timeline : true ,
6668 } )
67- )
69+ ) ,
70+ 'getUserTweets'
6871 ) ;
6972
7073const getUserTweetsAndReplies = ( id : string , params ?: Record < string , any > ) =>
71- cacheTryGet ( id , params , async ( id , params = { } ) =>
74+ cacheTryGet (
75+ id ,
76+ params ,
77+ async ( id , params = { } ) =>
7278 gatherLegacyFromData (
7379 await paginationTweets ( 'UserTweetsAndReplies' , id , {
7480 ...params ,
@@ -80,11 +86,15 @@ const getUserTweetsAndReplies = (id: string, params?: Record<string, any>) =>
8086 } ) ,
8187 [ 'profile-conversation-' ] ,
8288 id
83- )
89+ ) ,
90+ 'getUserTweetsAndReplies'
8491 ) ;
8592
8693const getUserMedia = ( id : string , params ?: Record < string , any > ) =>
87- cacheTryGet ( id , params , async ( id , params = { } ) =>
94+ cacheTryGet (
95+ id ,
96+ params ,
97+ async ( id , params = { } ) =>
8898 gatherLegacyFromData (
8999 await paginationTweets ( 'UserMedia' , id , {
90100 ...params ,
@@ -95,11 +105,15 @@ const getUserMedia = (id: string, params?: Record<string, any>) =>
95105 withVoice : true ,
96106 withV2Timeline : true ,
97107 } )
98- )
108+ ) ,
109+ 'getUserMedia'
99110 ) ;
100111
101112const getUserLikes = ( id : string , params ?: Record < string , any > ) =>
102- cacheTryGet ( id , params , async ( id , params = { } ) =>
113+ cacheTryGet (
114+ id ,
115+ params ,
116+ async ( id , params = { } ) =>
103117 gatherLegacyFromData (
104118 await paginationTweets ( 'Likes' , id , {
105119 ...params ,
@@ -109,11 +123,15 @@ const getUserLikes = (id: string, params?: Record<string, any>) =>
109123 withVoice : false ,
110124 withV2Timeline : true ,
111125 } )
112- )
126+ ) ,
127+ 'getUserLikes'
113128 ) ;
114129
115130const getUserTweet = ( id : string , params ?: Record < string , any > ) =>
116- cacheTryGet ( id , params , async ( id , params = { } ) =>
131+ cacheTryGet (
132+ id ,
133+ params ,
134+ async ( id , params = { } ) =>
117135 gatherLegacyFromData (
118136 await paginationTweets (
119137 'TweetDetail' ,
@@ -129,7 +147,8 @@ const getUserTweet = (id: string, params?: Record<string, any>) =>
129147 [ 'threaded_conversation_with_injections_v2' ]
130148 ) ,
131149 [ 'homeConversation-' , 'conversationthread-' ]
132- )
150+ ) ,
151+ 'getUserTweet'
133152 ) ;
134153
135154const getSearch = async ( keywords : string , params ?: Record < string , any > ) =>
0 commit comments