PIT: address PR suggestions

This commit is contained in:
carlosmonastyrski
2025-05-21 19:42:09 -03:00
parent 2493bbbc97
commit f06004370d
31 changed files with 862 additions and 576 deletions
@@ -21,7 +21,8 @@ export const folderCheckpointDALFactory = (db: TDbClient) => {
const findByCommitId = async (folderCommitId: string, tx?: Knex): Promise<TFolderCheckpoints | undefined> => {
try {
const doc = await (tx || db.replicaNode())<TFolderCheckpoints>(TableName.FolderCheckpoint)
.where({ folderCommitId })
// eslint-disable-next-line @typescript-eslint/no-misused-promises
.where(buildFindFilter({ folderCommitId }, TableName.FolderCheckpoint))
.select(selectAllTableCols(TableName.FolderCheckpoint))
.first();
return doc;
@@ -87,20 +88,11 @@ export const folderCheckpointDALFactory = (db: TDbClient) => {
};
const findNearestCheckpoint = async (
folderCommitId: string,
folderCommitId: bigint,
folderId: string,
tx?: Knex
): Promise<(CheckpointWithCommitInfo & { commitId: number }) | undefined> => {
): Promise<(CheckpointWithCommitInfo & { commitId: bigint }) | undefined> => {
try {
// First, get the commit info to find the folder ID and commit sequence number
const commit = await (tx || db.replicaNode())(TableName.FolderCommit)
.where({ id: folderCommitId })
.select("commitId", "folderId")
.first();
if (!commit) {
return undefined;
}
// Get the checkpoint with the highest commitId that's still less than or equal to our commit
const nearestCheckpoint = await (tx || db.replicaNode())(TableName.FolderCheckpoint)
.join<TFolderCommits>(
@@ -108,8 +100,8 @@ export const folderCheckpointDALFactory = (db: TDbClient) => {
`${TableName.FolderCheckpoint}.folderCommitId`,
`${TableName.FolderCommit}.id`
)
.where(`${TableName.FolderCommit}.folderId`, "=", commit.folderId)
.where(`${TableName.FolderCommit}.commitId`, "<=", commit.commitId)
.where(`${TableName.FolderCommit}.folderId`, "=", folderId)
.where(`${TableName.FolderCommit}.commitId`, "<=", folderCommitId)
.select(selectAllTableCols(TableName.FolderCheckpoint))
.select(
db.ref("actorMetadata").withSchema(TableName.FolderCommit),
@@ -121,7 +113,6 @@ export const folderCheckpointDALFactory = (db: TDbClient) => {
)
.orderBy(`${TableName.FolderCommit}.commitId`, "desc")
.first();
return nearestCheckpoint;
} catch (error) {
throw new DatabaseError({ error, name: "FindNearestCheckpoint" });