logs
Browse files- src/lib/db/trainerScanning.ts +14 -38
src/lib/db/trainerScanning.ts
CHANGED
|
@@ -7,13 +7,6 @@ export async function initializeTrainerScanProgress(imagePaths: string[]): Promi
|
|
| 7 |
console.log('π initializeTrainerScanProgress: Starting with', imagePaths.length, 'paths');
|
| 8 |
console.log('π initializeTrainerScanProgress: First few paths:', imagePaths.slice(0, 3));
|
| 9 |
|
| 10 |
-
console.log('π initializeTrainerScanProgress: Creating transaction...');
|
| 11 |
-
const tx = db.transaction([TRAINER_SCAN_STORE], 'readwrite');
|
| 12 |
-
console.log('π initializeTrainerScanProgress: Transaction created');
|
| 13 |
-
|
| 14 |
-
const store = tx.objectStore(TRAINER_SCAN_STORE);
|
| 15 |
-
console.log('π initializeTrainerScanProgress: Got object store');
|
| 16 |
-
|
| 17 |
let processedCount = 0;
|
| 18 |
let skippedCount = 0;
|
| 19 |
|
|
@@ -67,9 +60,9 @@ export async function initializeTrainerScanProgress(imagePaths: string[]): Promi
|
|
| 67 |
const remoteUrl = `https://huggingface.co/datasets/Fraser/piclets/resolve/main/${imagePath}`;
|
| 68 |
console.log(`π initializeTrainerScanProgress: Remote URL: ${remoteUrl}`);
|
| 69 |
|
| 70 |
-
// Check if this path already exists to avoid duplicates
|
| 71 |
console.log(`π initializeTrainerScanProgress: Checking for existing record...`);
|
| 72 |
-
const existing = await
|
| 73 |
console.log(`π initializeTrainerScanProgress: Existing record:`, existing ? 'found' : 'not found');
|
| 74 |
|
| 75 |
if (!existing) {
|
|
@@ -82,7 +75,7 @@ export async function initializeTrainerScanProgress(imagePaths: string[]): Promi
|
|
| 82 |
};
|
| 83 |
|
| 84 |
console.log(`π initializeTrainerScanProgress: Adding record:`, progressRecord);
|
| 85 |
-
await
|
| 86 |
console.log(`π initializeTrainerScanProgress: Record added successfully`);
|
| 87 |
processedCount++;
|
| 88 |
} else {
|
|
@@ -110,10 +103,6 @@ export async function initializeTrainerScanProgress(imagePaths: string[]): Promi
|
|
| 110 |
|
| 111 |
console.log(`β
Trainer scan initialization complete: ${processedCount} records processed, ${skippedCount} skipped`);
|
| 112 |
|
| 113 |
-
console.log('π initializeTrainerScanProgress: Completing transaction...');
|
| 114 |
-
await tx.complete;
|
| 115 |
-
console.log('π initializeTrainerScanProgress: Transaction completed successfully');
|
| 116 |
-
|
| 117 |
} catch (error) {
|
| 118 |
console.error('β initializeTrainerScanProgress: Fatal error during initialization:', error);
|
| 119 |
console.error('β initializeTrainerScanProgress: Error details:', {
|
|
@@ -126,22 +115,13 @@ export async function initializeTrainerScanProgress(imagePaths: string[]): Promi
|
|
| 126 |
|
| 127 |
// Get next pending image to process
|
| 128 |
export async function getNextPendingImage(): Promise<TrainerScanProgress | null> {
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
while (cursor) {
|
| 137 |
-
if (cursor.value.status === 'pending') {
|
| 138 |
-
pendingRecords.push(cursor.value);
|
| 139 |
-
}
|
| 140 |
-
cursor = await cursor.continue();
|
| 141 |
}
|
| 142 |
-
|
| 143 |
-
// Return the first pending record (if any)
|
| 144 |
-
return pendingRecords.length > 0 ? pendingRecords[0] : null;
|
| 145 |
}
|
| 146 |
|
| 147 |
// Update scan progress status
|
|
@@ -149,16 +129,12 @@ export async function updateScanProgress(
|
|
| 149 |
imagePath: string,
|
| 150 |
updates: Partial<Omit<TrainerScanProgress, 'id' | 'imagePath'>>
|
| 151 |
): Promise<void> {
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
const updated = { ...existing, ...updates };
|
| 158 |
-
await store.put(updated);
|
| 159 |
}
|
| 160 |
-
|
| 161 |
-
await tx.complete;
|
| 162 |
}
|
| 163 |
|
| 164 |
// Mark image processing as started
|
|
|
|
| 7 |
console.log('π initializeTrainerScanProgress: Starting with', imagePaths.length, 'paths');
|
| 8 |
console.log('π initializeTrainerScanProgress: First few paths:', imagePaths.slice(0, 3));
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
let processedCount = 0;
|
| 11 |
let skippedCount = 0;
|
| 12 |
|
|
|
|
| 60 |
const remoteUrl = `https://huggingface.co/datasets/Fraser/piclets/resolve/main/${imagePath}`;
|
| 61 |
console.log(`π initializeTrainerScanProgress: Remote URL: ${remoteUrl}`);
|
| 62 |
|
| 63 |
+
// Check if this path already exists to avoid duplicates (using Dexie syntax)
|
| 64 |
console.log(`π initializeTrainerScanProgress: Checking for existing record...`);
|
| 65 |
+
const existing = await db.trainerScanProgress.get(imagePath);
|
| 66 |
console.log(`π initializeTrainerScanProgress: Existing record:`, existing ? 'found' : 'not found');
|
| 67 |
|
| 68 |
if (!existing) {
|
|
|
|
| 75 |
};
|
| 76 |
|
| 77 |
console.log(`π initializeTrainerScanProgress: Adding record:`, progressRecord);
|
| 78 |
+
await db.trainerScanProgress.add(progressRecord);
|
| 79 |
console.log(`π initializeTrainerScanProgress: Record added successfully`);
|
| 80 |
processedCount++;
|
| 81 |
} else {
|
|
|
|
| 103 |
|
| 104 |
console.log(`β
Trainer scan initialization complete: ${processedCount} records processed, ${skippedCount} skipped`);
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
} catch (error) {
|
| 107 |
console.error('β initializeTrainerScanProgress: Fatal error during initialization:', error);
|
| 108 |
console.error('β initializeTrainerScanProgress: Error details:', {
|
|
|
|
| 115 |
|
| 116 |
// Get next pending image to process
|
| 117 |
export async function getNextPendingImage(): Promise<TrainerScanProgress | null> {
|
| 118 |
+
try {
|
| 119 |
+
const pendingRecord = await db.trainerScanProgress.where('status').equals('pending').first();
|
| 120 |
+
return pendingRecord || null;
|
| 121 |
+
} catch (error) {
|
| 122 |
+
console.error('β Failed to get next pending image:', error);
|
| 123 |
+
return null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
}
|
|
|
|
|
|
|
|
|
|
| 125 |
}
|
| 126 |
|
| 127 |
// Update scan progress status
|
|
|
|
| 129 |
imagePath: string,
|
| 130 |
updates: Partial<Omit<TrainerScanProgress, 'id' | 'imagePath'>>
|
| 131 |
): Promise<void> {
|
| 132 |
+
try {
|
| 133 |
+
await db.trainerScanProgress.update(imagePath, updates);
|
| 134 |
+
} catch (error) {
|
| 135 |
+
console.error(`β Failed to update scan progress for ${imagePath}:`, error);
|
| 136 |
+
throw error;
|
|
|
|
|
|
|
| 137 |
}
|
|
|
|
|
|
|
| 138 |
}
|
| 139 |
|
| 140 |
// Mark image processing as started
|