Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ export class DeploymentRepository {
return deployments ? (deployments as unknown as StaleDeploymentsOutput[]) : [];
}

async findAllWithGpuResources(minHeight: number) {
return await Deployment.findAll({
attributes: ["id", "owner"],
where: { createdHeight: { [Op.gte]: minHeight } },
async *findAllWithGpuResources(options: { minHeight: number }) {
// First, get all deployment IDs matching the criteria (lightweight query)
const recordsWithIds = await Deployment.findAll({
attributes: ["id"],
where: { createdHeight: { [Op.gte]: options.minHeight } },
include: [
{
attributes: [],
Expand All @@ -121,24 +122,44 @@ export class DeploymentRepository {
where: { gpuUnits: 1 }
}
]
},
{
attributes: ["height", "data", "type"],
model: AkashMessage,
as: "relatedMessages",
where: {
type: {
[Op.or]: ["/akash.market.v1beta4.MsgCreateBid", "/akash.market.v1beta5.MsgCreateBid"]
},
height: { [Op.gte]: minHeight }
},
include: [
{ model: Block, attributes: ["height", "dayId", "datetime"], required: true },
{ model: Transaction, attributes: ["hash"], required: true }
]
}
]
],
raw: true
});

const ids = recordsWithIds.map(r => r.id);
const BATCH_SIZE = 200;

// Iterate over IDs in batches and yield each deployment
for (let i = 0; i < ids.length; i += BATCH_SIZE) {
const batchIds = ids.slice(i, i + BATCH_SIZE);

const batch = await Deployment.findAll({
attributes: ["id", "owner"],
where: { id: { [Op.in]: batchIds } },
include: [
{
attributes: ["height", "data", "type"],
model: AkashMessage,
as: "relatedMessages",
where: {
type: {
[Op.or]: ["/akash.market.v1beta4.MsgCreateBid", "/akash.market.v1beta5.MsgCreateBid"]
},
height: { [Op.gte]: options.minHeight }
},
include: [
{ model: Block, attributes: ["height", "dayId", "datetime"], required: true },
{ model: Transaction, attributes: ["hash"], required: true }
]
}
]
});

for (const deployment of batch) {
yield deployment;
}
}
}

async findByIdWithGroups(owner: string, dseq: string): Promise<Deployment | null> {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/gpu/controllers/gpu.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { singleton } from "tsyringe";

import { GpuBreakdownQuery } from "@src/gpu/http-schemas/gpu.schema";
import { GpuService } from "@src/gpu/services/gpu.service";
import { GpuPriceService } from "@src/gpu/services/gpu-price.service";
import { GpuPriceService } from "@src/gpu/services/gpu-price/gpu-price.service";

@singleton()
export class GpuController {
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/gpu/repositories/day.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { singleton } from "tsyringe";

@singleton()
export class DayRepository {
async getDaysAfter(date: Date) {
return await Day.findAll({ where: { date: { [Op.gte]: date } } });
async getDaysAfter(date: Date): Promise<Day[]> {
return await Day.findAll({ where: { date: { [Op.gte]: date } }, raw: true });
}
}
Loading