minimal speedup of migration
authorPhiTux <redacted>
Sat, 19 Jul 2025 15:07:30 +0000 (17:07 +0200)
committerPhiTux <redacted>
Sat, 19 Jul 2025 15:07:30 +0000 (17:07 +0200)
backend/utils/migration.go

index da69b731b1449ee07fe813e48b0ad4410c3d5d93..7c9b59c6cb4d308ce22de64fc6b1c4c8b2bbd423 100644 (file)
@@ -625,6 +625,12 @@ func migrateLogs(oldDir, newDir string, oldKey string, newKey string, progress *
 
        processedMonths := 0
 
+       oldKeyBytes, err := base64.URLEncoding.DecodeString(oldKey)
+       if err != nil {
+               Logger.Printf("Error decoding oldKey %v", err)
+               progress.ErrorCount++
+       }
+
        // Process all months
        for _, monthInfo := range allMonthFiles {
 
@@ -679,13 +685,6 @@ func migrateLogs(oldDir, newDir string, oldKey string, newKey string, progress *
                        continue
                }
 
-               oldKeyBytes, err := base64.URLEncoding.DecodeString(oldKey)
-               if err != nil {
-                       Logger.Printf("Error decoding oldKey %v", err)
-                       progress.ErrorCount++
-                       continue
-               }
-
                // Loop through all days and decrypt/encrypt the texts
                for i, dayInterface := range days {
                        day, ok := dayInterface.(map[string]any)
@@ -1070,13 +1069,12 @@ func migrateFiles(oldFilesDir, newDir string, oldKey string, newKey string, prog
 
                processedFiles++
 
-               // Update progress occasionally
-               if i%5 == 0 || i == len(fileRefs)-1 {
-                       progress.ProcessedItems = processedFiles
-                       if progressChan != nil {
-                               progressChan <- *progress
-                       }
+               // Update progress
+               progress.ProcessedItems = processedFiles
+               if progressChan != nil {
+                       progressChan <- *progress
                }
+
        }
 
        // Third pass: update all month files with new file IDs
git clone https://git.99rst.org/PROJECT