File tree Expand file tree Collapse file tree 3 files changed +20
-17
lines changed
Expand file tree Collapse file tree 3 files changed +20
-17
lines changed Original file line number Diff line number Diff line change @@ -156,27 +156,11 @@ export class AppComponent implements OnInit {
156156 return ;
157157 }
158158
159- this . cachedApi . getAllSafelistedInstances ( { } , { ttl : 600 } ) . subscribe ( instancesResponse => {
159+ this . cachedApi . getAllInstances ( { ttl : 3600 } ) . subscribe ( instancesResponse => {
160160 if ( this . apiResponseHelper . handleErrors ( [ instancesResponse ] ) ) {
161161 return ;
162162 }
163163
164- const allInstances = instancesResponse . successResponse ! . instances . map ( instance => instance . domain ) ;
165- this . cachedApi . getAllCensuresByInstances ( allInstances , { ttl : 600 } ) . subscribe ( instancesResponse => {
166- if ( this . apiResponseHelper . handleErrors ( [ instancesResponse ] ) ) {
167- return ;
168- }
169- const instances = instancesResponse . successResponse ! . instances . filter (
170- instance => instance . domain . includes ( searchText ) ,
171- ) ;
172- for ( const instance of instances ) {
173- this . searchResults [ instance . domain ] = {
174- title : instance . domain ,
175- link : `/instances/detail/${ instance . domain } `
176- } ;
177- }
178- } ) ;
179-
180164 const instances = instancesResponse . successResponse ! . instances . filter (
181165 instance => instance . domain . includes ( searchText ) ,
182166 ) ;
Original file line number Diff line number Diff line change @@ -124,6 +124,21 @@ export class CachedFediseerApiService {
124124 ) ;
125125 }
126126
127+ public getAllInstances ( cacheConfig : CacheConfiguration = { } ) : Observable < ApiResponse < InstanceListResponse < InstanceDetailResponse > > > {
128+ cacheConfig . type ??= CacheType . Permanent ;
129+ cacheConfig . ttl ??= 3600 ;
130+
131+ const cacheKey = `api.all_instances${ cacheConfig . ttl } ` ;
132+ const item = this . getCacheItem < InstanceListResponse < InstanceDetailResponse > > ( cacheKey , cacheConfig ) ! ;
133+ if ( item . isHit && ! cacheConfig . clear ) {
134+ return this . getSuccessResponse ( item ) ;
135+ }
136+
137+ return this . api . allInstances . pipe (
138+ tap ( this . storeResponse ( item , cacheConfig ) ) ,
139+ ) ;
140+ }
141+
127142 public clearSafelistCache ( ) : void {
128143 this . runtimeCache . clearByPrefix ( 'api.safelist' ) ;
129144 this . permanentCache . clearByPrefix ( 'api.safelist' ) ;
Original file line number Diff line number Diff line change @@ -281,6 +281,10 @@ export class FediseerApiService {
281281 ) ;
282282 }
283283
284+ public get allInstances ( ) : Observable < ApiResponse < InstanceListResponse < InstanceDetailResponse > > > {
285+ return this . sendRequest ( HttpMethod . Get , `all_instances` ) ;
286+ }
287+
284288 public getAllSafelistedInstances ( filter : SafelistFilter = { } ) : Observable < ApiResponse < InstanceListResponse < InstanceDetailResponse > > > {
285289 let body : { [ key : string ] : string } = { } ;
286290 if ( filter . tags !== undefined ) {
You can’t perform that action at this time.
0 commit comments