Skip to content

Commit 7b092cc

Browse files
authored
Feat: Use a different endpoint for search bar (#192)
1 parent 3921764 commit 7b092cc

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/app/app.component.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff 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
);

src/app/services/cached-fediseer-api.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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');

src/app/services/fediseer-api.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)