mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 18:34:09 +00:00
fix(places): the second CI run, split the library reads and test the rating order
The reads of what an entry of All places keeps beside its facts (tags, notes, votes, planned days, bookings, list roles) move from PlacesLibraryRepository into PlacesLibraryDetailsRepository, so neither file passes the size limit. New end to end tests cover the rating filter, the tab counts under it, the rating order and its cursor, and list_all_places with both. The test types follow the vote shapes, the edit target says it may be null, the bookings pair names the booking card that now holds the booking model, and the size baselines drop to the measured lengths.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { LibraryOwnedTagRow, LibraryTripTagRow } from '../../db/repositories/PlacesLibrary.repository';
|
||||
import type { LibraryOwnedTagRow, LibraryTripTagRow } from '../../db/repositories/PlacesLibraryDetails.repository';
|
||||
import type { EntryRows } from './places-library.helpers';
|
||||
import type { PlacesLibraryEntryTag, PlacesLibraryTag } from '@trek/shared';
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { LibraryOwnVoteRow, LibraryUseRow } from '../../db/repositories/PlacesLibrary.repository';
|
||||
import type { LibraryUseRow } from '../../db/repositories/PlacesLibrary.repository';
|
||||
import type { LibraryOwnVoteRow } from '../../db/repositories/PlacesLibraryDetails.repository';
|
||||
import { castAfter, type EntryRows } from './places-library.helpers';
|
||||
|
||||
/** The copies of a place a vote lands on: trip places with their trip, and saved places. */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ADDON_IDS } from '../../addons';
|
||||
import type { PlaceWithTagsRow } from '../../db/repositories/Places.repository';
|
||||
import { PlacesLibraryRepository } from '../../db/repositories/PlacesLibrary.repository';
|
||||
import { PlacesLibraryDetailsRepository } from '../../db/repositories/PlacesLibraryDetails.repository';
|
||||
import { AddonsService } from '../addons/addons.service';
|
||||
import { logError } from '../audit/audit-log.logger';
|
||||
import { CollectionsService } from '../collections/collections.service';
|
||||
@@ -64,7 +64,7 @@ export class PlaceVotesService implements OnModuleInit {
|
||||
private readonly collections: CollectionsService,
|
||||
private readonly places: PlacesService,
|
||||
private readonly uow: UnitOfWork,
|
||||
private readonly repo: PlacesLibraryRepository,
|
||||
private readonly details: PlacesLibraryDetailsRepository,
|
||||
private readonly addons: AddonsService,
|
||||
private readonly membership: TripMembershipService,
|
||||
) {}
|
||||
@@ -180,7 +180,7 @@ export class PlaceVotesService implements OnModuleInit {
|
||||
|
||||
/** Up to `limit` people with a vote anywhere, by id, after `after`: the pages of carryOver's pass. */
|
||||
async voters(after: number, limit: number): Promise<number[]> {
|
||||
return this.repo.voterIds(after, limit);
|
||||
return this.details.voterIds(after, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,7 +231,7 @@ export class PlaceVotesService implements OnModuleInit {
|
||||
return this.uow.transactional(async () => {
|
||||
const reach = await this.library.reach(userId);
|
||||
const uses = await this.library.usesOf(reach, null);
|
||||
const carried = votesToCarry(uses, await this.repo.votesOfUser(userId));
|
||||
const carried = votesToCarry(uses, await this.details.votesOfUser(userId));
|
||||
if (carried.length === 0) return [];
|
||||
const anchorOf = new Map(uses.map((use) => [`${use.from_list}:${use.use_id}`, use.anchor_key]));
|
||||
const anchors = new Set(carried.map((vote) => anchorOf.get(`${vote.fromList}:${vote.useId}`) ?? 0));
|
||||
|
||||
@@ -7,11 +7,11 @@ import {
|
||||
type LibraryCollectionPlaceRow,
|
||||
type LibraryIdentityRow,
|
||||
type LibraryPosition,
|
||||
type LibraryRatingRow,
|
||||
type LibrarySort,
|
||||
type LibraryTripPlaceRow,
|
||||
type LibraryUseRow,
|
||||
} from '../../db/repositories/PlacesLibrary.repository';
|
||||
import type { LibraryRatingRow } from '../../db/repositories/PlacesLibraryDetails.repository';
|
||||
import { avatarUrl } from '../common/avatarUrl';
|
||||
import {
|
||||
collectionStatusSchema,
|
||||
|
||||
@@ -4,6 +4,7 @@ import { UserPlaceMerges } from '../../db/entities/UserPlaceMerges.entity';
|
||||
import { UserPlaces } from '../../db/entities/UserPlaces.entity';
|
||||
import { PlaceVisitContextRepository } from '../../db/repositories/PlaceVisitContext.repository';
|
||||
import { PlacesLibraryRepository } from '../../db/repositories/PlacesLibrary.repository';
|
||||
import { PlacesLibraryDetailsRepository } from '../../db/repositories/PlacesLibraryDetails.repository';
|
||||
import { AddonsModule } from '../addons/addons.module';
|
||||
import { CollectionsModule } from '../collections/collections.module';
|
||||
import { McpSharedModule } from '../mcp-shared/mcp-shared.module';
|
||||
@@ -51,6 +52,11 @@ import { Module } from '@nestjs/common';
|
||||
useFactory: (em: EntityManager) => new PlacesLibraryRepository(em),
|
||||
inject: [EntityManager],
|
||||
},
|
||||
{
|
||||
provide: PlacesLibraryDetailsRepository,
|
||||
useFactory: (em: EntityManager) => new PlacesLibraryDetailsRepository(em),
|
||||
inject: [EntityManager],
|
||||
},
|
||||
{
|
||||
provide: PlaceVisitContextRepository,
|
||||
useFactory: (em: EntityManager) => new PlaceVisitContextRepository(em),
|
||||
@@ -66,6 +72,12 @@ import { Module } from '@nestjs/common';
|
||||
PlaceIdentitiesPruneJob,
|
||||
],
|
||||
// The visits and media (PlaceVisitsModule) and the votes (PlaceVotesModule) of All places, same domain, read through these.
|
||||
exports: [PlacesLibraryService, PlaceVisitsReaderService, PlaceVisitContextRepository, PlacesLibraryRepository],
|
||||
exports: [
|
||||
PlacesLibraryService,
|
||||
PlaceVisitsReaderService,
|
||||
PlaceVisitContextRepository,
|
||||
PlacesLibraryRepository,
|
||||
PlacesLibraryDetailsRepository,
|
||||
],
|
||||
})
|
||||
export class PlacesLibraryModule {}
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
type LibraryTripPlaceRow,
|
||||
type LibraryUseRow,
|
||||
} from '../../db/repositories/PlacesLibrary.repository';
|
||||
import { PlacesLibraryDetailsRepository } from '../../db/repositories/PlacesLibraryDetails.repository';
|
||||
import { CollectionsService } from '../collections/collections.service';
|
||||
import { badRequest, notFound } from '../common/domain-error';
|
||||
import { PermissionsService } from '../permissions/permissions.service';
|
||||
@@ -101,6 +102,7 @@ function armsOfReach(reach: LibraryReach): LibraryArms {
|
||||
export class PlacesLibraryService {
|
||||
constructor(
|
||||
private readonly repo: PlacesLibraryRepository,
|
||||
private readonly kept: PlacesLibraryDetailsRepository, // what each entry keeps beside its facts
|
||||
private readonly collections: CollectionsService,
|
||||
private readonly membership: TripMembershipService,
|
||||
private readonly permissions: PermissionsService,
|
||||
@@ -256,11 +258,11 @@ export class PlacesLibraryService {
|
||||
const placeIds = rows.flatMap((row) => row.trips.map((trip) => trip.id));
|
||||
const savedIds = rows.flatMap((row) => row.saved.map((saved) => saved.id));
|
||||
const onTrips = groupBy(
|
||||
await readInChunks(placeIds, (chunk) => this.repo.tripPlaceRatings(chunk)),
|
||||
await readInChunks(placeIds, (chunk) => this.kept.tripPlaceRatings(chunk)),
|
||||
(vote) => vote.target_id,
|
||||
);
|
||||
const onLists = groupBy(
|
||||
await readInChunks(savedIds, (chunk) => this.repo.savedPlaceRatings(chunk)),
|
||||
await readInChunks(savedIds, (chunk) => this.kept.savedPlaceRatings(chunk)),
|
||||
(vote) => vote.target_id,
|
||||
);
|
||||
return rows.map((row) =>
|
||||
@@ -278,8 +280,8 @@ export class PlacesLibraryService {
|
||||
private async tagsOf(rows: readonly EntryRows[]): Promise<PlacesLibraryEntryTag[][]> {
|
||||
const placeIds = rows.flatMap((row) => row.trips.map((trip) => trip.id));
|
||||
const savedIds = rows.flatMap((row) => row.saved.map((saved) => saved.id));
|
||||
const tripTags = await readInChunks(placeIds, (chunk) => this.repo.tripPlaceTags(chunk));
|
||||
const labels = await readInChunks(savedIds, (chunk) => this.repo.savedPlaceLabels(chunk));
|
||||
const tripTags = await readInChunks(placeIds, (chunk) => this.kept.tripPlaceTags(chunk));
|
||||
const labels = await readInChunks(savedIds, (chunk) => this.kept.savedPlaceLabels(chunk));
|
||||
return entryTagsOf(rows, tripTags, labels);
|
||||
}
|
||||
|
||||
@@ -301,7 +303,7 @@ export class PlacesLibraryService {
|
||||
saved: readonly LibraryCollectionPlaceRow[],
|
||||
): Promise<OriginAccess> {
|
||||
const listIds = [...new Set(saved.map((row) => row.collection_id))];
|
||||
const roles = listIds.length > 0 ? await this.repo.collectionRoles(user.id, listIds) : [];
|
||||
const roles = listIds.length > 0 ? await this.kept.collectionRoles(user.id, listIds) : [];
|
||||
const editableLists = new Set(roles.filter((role) => role.role !== 'viewer').map((role) => role.id));
|
||||
const asOwner = trips.some((row) => row.trip_owner_id === user.id)
|
||||
? await this.permissions.checkPermission('place_edit', user.role, user.id, user.id, false)
|
||||
@@ -325,12 +327,12 @@ export class PlacesLibraryService {
|
||||
const details: PlacesLibraryDetail[] = [];
|
||||
if (rows.trips.length > 0) {
|
||||
const placeIds = rows.trips.map((row) => row.id);
|
||||
const notes = new Map((await this.repo.tripPlaceNotes(placeIds)).map((row) => [row.id, row.notes]));
|
||||
const ratings = groupBy(await this.repo.tripPlaceRatings(placeIds), (row) => row.target_id);
|
||||
const days = groupBy(await this.repo.plannedDays(placeIds), (row) => row.place_id);
|
||||
const booked = await this.repo.bookedPlaces(placeIds);
|
||||
const tags = groupBy(await this.repo.tripPlaceTags(placeIds), (row) => row.place_id);
|
||||
const tripTags = tagsByOwner(await this.repo.tripTags([...new Set(rows.trips.map((row) => row.trip_id))]));
|
||||
const notes = new Map((await this.kept.tripPlaceNotes(placeIds)).map((row) => [row.id, row.notes]));
|
||||
const ratings = groupBy(await this.kept.tripPlaceRatings(placeIds), (row) => row.target_id);
|
||||
const days = groupBy(await this.kept.plannedDays(placeIds), (row) => row.place_id);
|
||||
const booked = await this.kept.bookedPlaces(placeIds);
|
||||
const tags = groupBy(await this.kept.tripPlaceTags(placeIds), (row) => row.place_id);
|
||||
const tripTags = tagsByOwner(await this.kept.tripTags([...new Set(rows.trips.map((row) => row.trip_id))]));
|
||||
for (const row of rows.trips) {
|
||||
const assigned = (tags.get(row.id) ?? []).map(tagOf);
|
||||
details.push({
|
||||
@@ -357,11 +359,11 @@ export class PlacesLibraryService {
|
||||
}
|
||||
if (rows.saved.length > 0) {
|
||||
const savedIds = rows.saved.map((row) => row.id);
|
||||
const notes = new Map((await this.repo.savedPlaceNotes(savedIds)).map((row) => [row.id, row.notes]));
|
||||
const labels = groupBy(await this.repo.savedPlaceLabels(savedIds), (row) => row.collection_place_id);
|
||||
const ratings = groupBy(await this.repo.savedPlaceRatings(savedIds), (row) => row.target_id);
|
||||
const notes = new Map((await this.kept.savedPlaceNotes(savedIds)).map((row) => [row.id, row.notes]));
|
||||
const labels = groupBy(await this.kept.savedPlaceLabels(savedIds), (row) => row.collection_place_id);
|
||||
const ratings = groupBy(await this.kept.savedPlaceRatings(savedIds), (row) => row.target_id);
|
||||
const listTags = tagsByOwner(
|
||||
await this.repo.listLabels([...new Set(rows.saved.map((row) => row.collection_id))]),
|
||||
await this.kept.listLabels([...new Set(rows.saved.map((row) => row.collection_id))]),
|
||||
);
|
||||
for (const row of rows.saved) {
|
||||
const assigned = (labels.get(row.id) ?? []).map(tagOf);
|
||||
|
||||
Reference in New Issue
Block a user