Skip to content

Commit

Permalink
fix: return sdk id that always has snippets (#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Oct 31, 2024
1 parent 9a9e88b commit 227a2b1
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion servers/fdr/src/db/sdk/SdkDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ export class SdkDaoImpl implements SdkDao {
}
}

const sdkRow = await this.prisma.sdk.findFirst({
// Get all SDK rows ordered by creation date
const sdkRows = await this.prisma.sdk.findMany({
select: {
id: true,
},
Expand All @@ -177,7 +178,25 @@ export class SdkDaoImpl implements SdkDao {
orderBy: {
createdAt: "desc",
},
take: 10,
});

// Find first SDK that has snippets
for (const sdkRow of sdkRows) {
const hasSnippets = await this.prisma.snippet.findFirst({
where: {
sdkId: sdkRow.id,
},
});

if (hasSnippets) {
return sdkRow?.id;
}
}

// If no SDKs have snippets, return the most recent one
const sdkRow = sdkRows[0];

LOGGER.info(`Looking for latest registered SDK ${sdkPackage} and found id ${sdkRow?.id}`);
return sdkRow?.id;
}
Expand Down

0 comments on commit 227a2b1

Please sign in to comment.