fix(db): add missing indexes, bound unbounded queries, parallelize admin queries
- Add 7 missing indexes: User(kycStatus, isActive, createdAt), Listing(createdAt, featuredUntil, expiresAt), Payment(createdAt) - Add take:50 limit to unbounded findMediaByPropertyId and findByPropertyId - Parallelize sequential queries in getUserDetail with Promise.all Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -220,21 +220,22 @@ export class PrismaAdminQueryRepository implements IAdminQueryRepository {
|
||||
|
||||
if (!user) return null;
|
||||
|
||||
const transactionsCount = await this.prisma.transaction.count({
|
||||
where: { buyerId: userId },
|
||||
});
|
||||
|
||||
const recentListings = await this.prisma.listing.findMany({
|
||||
where: { sellerId: userId },
|
||||
select: {
|
||||
id: true,
|
||||
status: true,
|
||||
createdAt: true,
|
||||
property: { select: { title: true } },
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 10,
|
||||
});
|
||||
const [transactionsCount, recentListings] = await Promise.all([
|
||||
this.prisma.transaction.count({
|
||||
where: { buyerId: userId },
|
||||
}),
|
||||
this.prisma.listing.findMany({
|
||||
where: { sellerId: userId },
|
||||
select: {
|
||||
id: true,
|
||||
status: true,
|
||||
createdAt: true,
|
||||
property: { select: { title: true } },
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 10,
|
||||
}),
|
||||
]);
|
||||
|
||||
const recentActivity = recentListings.map((l) => ({
|
||||
type: 'listing',
|
||||
|
||||
@@ -17,6 +17,7 @@ export class PrismaValuationRepository implements IValuationRepository {
|
||||
const records = await this.prisma.valuation.findMany({
|
||||
where: { propertyId },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 50,
|
||||
});
|
||||
return records.map((r) => this.toDomain(r));
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ export class PrismaPropertyRepository implements IPropertyRepository {
|
||||
const mediaList = await this.prisma.propertyMedia.findMany({
|
||||
where: { propertyId },
|
||||
orderBy: { order: 'asc' },
|
||||
take: 50,
|
||||
});
|
||||
return mediaList.map((m) => this.toMediaDomain(m));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user