Skip to content

Commit 4b2aa40

Browse files
committed
feat(rack-browser): only show racks with modules
1 parent e634799 commit 4b2aa40

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

src/app/features/backend/supabase.service.ts

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ type CachedEntity =
112112
| 'patches'
113113
| 'currentUserComments'
114114
| 'rackWithId'
115+
| 'racksMinimal'
115116
| void;
116117
const cacheBuster$ = new Subject<CachedEntity[]>();
117118

@@ -173,6 +174,7 @@ export class SupabaseService {
173174
currentUserComments: typeof SupabaseService.prototype.getCurrentUserComments;
174175
patches: typeof SupabaseService.prototype.getPatches;
175176
rackWithId: typeof SupabaseService.prototype.getRackWithId;
177+
racksMinimal: typeof SupabaseService.prototype.getRacksMinimal;
176178
} = {
177179
currentUserModules: this.getCurrentUserModules.bind(this),
178180
modules: this.getModules.bind(this),
@@ -183,7 +185,8 @@ export class SupabaseService {
183185
patchConnections: this.getPatchConnections.bind(this),
184186
currentUserComments: this.getCurrentUserComments.bind(this),
185187
patches: this.getPatches.bind(this),
186-
rackWithId: this.getRackWithId.bind(this)
188+
rackWithId: this.getRackWithId.bind(this),
189+
racksMinimal: this.getRacksMinimal.bind(this)
187190
};
188191

189192
readonly cacheResetter$ = cacheBuster$;
@@ -247,19 +250,7 @@ export class SupabaseService {
247250
rackid: y.rackid
248251
}
249252
})))),
250-
racksMinimal: (from = 0, to: number = this.defaultPag, name?: string, orderBy?: string, orderDirection?: string) => rxFrom(
251-
this.supabase.from(DbPaths.racks)
252-
.select(`id,name,hp,rows,description,created,updated,authorid,${ QueryJoins.author },image`, {count: 'exact'})
253-
// only public
254-
.filter('public', 'eq', true)
255-
.ilike(`name,hp,rows, ${ QueryJoins.author }`, `%${ name }%`)
256-
.range(from, to)
257-
.order(orderBy ? orderBy : 'name', {ascending: orderDirection === 'asc'})
258-
)
259-
.pipe(
260-
remapErrors(),
261-
map((x: any) => x), // map type as any , TODO: fix this
262-
),
253+
263254
racksWithModule: (moduleid: number, from = 0, to: number = this.defaultPag, orderBy?: string, orderDirection?: 'asc' | 'desc') => rxFrom(
264255
this.supabase.from(DbPaths.rack_modules_grouped_by_moduleid)
265256
.select(`*,${ QueryJoins.rack }`, {count: 'exact'})
@@ -1046,6 +1037,47 @@ export class SupabaseService {
10461037
);
10471038
}
10481039

1040+
@Cacheable({
1041+
maxAge: defaultCacheTime,
1042+
cacheBusterObserver: cacheBuster$.pipe(filter(x => x.includes('racksMinimal'))),
1043+
maxCacheCount: 50,
1044+
})
1045+
private getRacksMinimal(
1046+
from: number = 0,
1047+
to?: number,
1048+
name?: string,
1049+
orderBy?: string,
1050+
orderDirection?: string
1051+
) {
1052+
const effectiveTo = to ?? this.defaultPag;
1053+
1054+
const columns = [
1055+
"id",
1056+
"name",
1057+
"hp",
1058+
"rows",
1059+
"description",
1060+
"created",
1061+
"updated",
1062+
"authorid",
1063+
QueryJoins.author,
1064+
"image"
1065+
].join(",");
1066+
1067+
return rxFrom(
1068+
this.supabase.from(DbPaths.racks)
1069+
.select(`${ columns }, rack_modules!inner(rackid)`, {count: "exact"})
1070+
.filter("public", "eq", true)
1071+
.ilike(`name,hp,rows,${ QueryJoins.author }`, `%${ name.trim().toLowerCase() }%`)
1072+
.range(from, effectiveTo)
1073+
.order(orderBy ? orderBy : "name", {ascending: orderDirection === "asc"})
1074+
)
1075+
.pipe(
1076+
remapErrors(),
1077+
map((x: any) => x)
1078+
);
1079+
}
1080+
10491081
@Cacheable({
10501082
maxAge: longCacheTime,
10511083
cacheBusterObserver: cacheBuster$.pipe(filter(x => x.includes('currentUserComments'))),

src/app/features/routes/rack/rack-browser-data.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ export class RackBrowserDataService implements OnDestroy {
169169
const sortDirection = sort[1];
170170

171171
// return this.backend.get.racks(skip, (skip + take) - 1, filter, sortColumnName);
172-
return this.backend.get.racksMinimal(skip, (skip + take) - 1, filter, sortColumnName, sortDirection);
172+
return this.backend.GET.racksMinimal(skip, (skip + take) - 1, filter, sortColumnName, sortDirection);
173173
}),
174174
takeUntil(this.destroyEvent$)
175175
)
176-
.subscribe(x => {
176+
.subscribe((x: any) => {
177177
this.serversideAdditionalData.itemsCount$.next(x.count);
178178
this.racksList$.next(x.data);
179179

0 commit comments

Comments
 (0)