Skip to content

Commit

Permalink
refactor(config): Comment out property processing code in deno-kv
Browse files Browse the repository at this point in the history
  • Loading branch information
csulit committed Oct 25, 2024
1 parent 45e00b1 commit a38fbee
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions config/deno-kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,44 +466,44 @@ export async function listenQueue(kv: Deno.Kv) {
`SELECT * FROM Property WHERE ai_generated_description IS NULL LIMIT 10 ORDER BY created_at DESC`
);

if (property.rowCount && property.rowCount > 0) {
// Process properties in parallel with rate limiting
const processProperty = async (row: unknown) => {
const propertyData = row as {
id: number;
};

const aiGeneratedDescription = await openaiAssistant(
JSON.stringify(row)
);

if (aiGeneratedDescription) {
processedProperty.push({
id: propertyData.id,
ai_generated_description: aiGeneratedDescription,
});
}
};

// Process 2 properties at a time with 5s delay between batches
for (let i = 0; i < property.rows.length; i += 2) {
const batch = property.rows.slice(i, i + 2);
await Promise.all(batch.map(processProperty));
if (i + 2 < property.rows.length) {
await new Promise((resolve) => setTimeout(resolve, 5000));
}
}

// Update all processed properties in transaction
// for (const prop of processedProperty) {
// await transaction.queryObject({
// args: [prop.ai_generated_description, prop.id],
// text: `UPDATE Property SET ai_generated_description = $1 WHERE id = $2`,
// });
// }
}

console.log(processedProperty);
// if (property.rowCount && property.rowCount > 0) {
// // Process properties in parallel with rate limiting
// const processProperty = async (row: unknown) => {
// const propertyData = row as {
// id: number;
// };

// const aiGeneratedDescription = await openaiAssistant(
// JSON.stringify(row)
// );

// if (aiGeneratedDescription) {
// processedProperty.push({
// id: propertyData.id,
// ai_generated_description: aiGeneratedDescription,
// });
// }
// };

// // Process 2 properties at a time with 5s delay between batches
// for (let i = 0; i < property.rows.length; i += 2) {
// const batch = property.rows.slice(i, i + 2);
// await Promise.all(batch.map(processProperty));
// if (i + 2 < property.rows.length) {
// await new Promise((resolve) => setTimeout(resolve, 5000));
// }
// }

// // Update all processed properties in transaction
// for (const prop of processedProperty) {
// await transaction.queryObject({
// args: [prop.ai_generated_description, prop.id],
// text: `UPDATE Property SET ai_generated_description = $1 WHERE id = $2`,
// });
// }
// }

console.log(property);

await transaction.commit();
console.log("Transaction successfully committed for create");
Expand Down

0 comments on commit a38fbee

Please sign in to comment.