From 0b4eb08a3f5cc6dffd91425f3c30ac3d88c2ef2e Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 22 Jun 2025 13:12:27 +0300 Subject: [PATCH] =?UTF-8?q?reaper:=20=D1=8F=20=D1=83=D0=B6=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=BD=D0=B0=D1=8E=20=D1=87=D1=82=D0=BE=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B6=D0=BD=D0=BE=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BB=D1=83=D1=87=D1=88=D0=B5,=20=D0=BA=D1=83=D0=BF?= =?UTF-8?q?=D0=B8=D1=82=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=BF=D1=8C=D1=8E=D1=82?= =?UTF-8?q?=D0=B5=D1=80=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D1=88=D0=B5=20?= =?UTF-8?q?=D1=85=D0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/book-reaper/internal/app/app.go | 42 +++++++++++++--------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/apps/book-reaper/internal/app/app.go b/apps/book-reaper/internal/app/app.go index 739cbe5..8333a2e 100644 --- a/apps/book-reaper/internal/app/app.go +++ b/apps/book-reaper/internal/app/app.go @@ -39,7 +39,7 @@ func (a *App) Run() error { totalZips := len(zipFiles) fmt.Printf("Found %d archives\n", totalZips) - jobChan := make(chan BookJob, 2500) + jobChan := make(chan BookJob, 1000) var dbWg sync.WaitGroup var processedCount uint64 = 0 @@ -104,7 +104,7 @@ func findZipFiles(basePath string) []string { } func processZipFilesParallel(basePath string, zipFiles []string, jobChan chan<- BookJob, processedCount *uint64, totalZips int) { - const workers = 8 + const workers = 16 var wg sync.WaitGroup tasks := make(chan string, workers) @@ -140,7 +140,7 @@ func processZipFilesParallel(basePath string, zipFiles []string, jobChan chan<- func processZip(basePath string, zipPath string, jobChan chan<- BookJob) { r, err := zip.OpenReader(zipPath) if err != nil { - log.Printf("Failed open zip: %v\n", err) + log.Printf("Failed open zip: %v, %s\n", err, zipPath) return } bookcase, err := filepath.Rel(basePath, zipPath) @@ -149,29 +149,25 @@ func processZip(basePath string, zipPath string, jobChan chan<- BookJob) { return } defer r.Close() - var wg sync.WaitGroup + for _, f := range r.File { if strings.HasSuffix(strings.ToLower(f.Name), ".fb2") { - wg.Add(1) - go func() { - defer wg.Done() - rc, err := f.Open() - if err != nil { - log.Printf("Unable read file from archive: %v\n", err) - return - } - rawFB2 := reaper.Parse(rc) - _ = rc.Close() + rc, err := f.Open() + if err != nil { + log.Printf("Unable read file from archive: %v\n", err) + return + } + rawFB2 := reaper.Parse(rc) + _ = rc.Close() - if rawFB2 == nil { - // log.Printf("Не удалось распарсить: %s\n", f.Name) - return - } - fb2 := reaper.RawToFB2(*rawFB2, f.FileInfo().Name(), &bookcase, f.UncompressedSize64, nil) - log.Println("paersed book", fb2.Title) - jobChan <- BookJob{FB2: fb2} - }() + if rawFB2 == nil { + // log.Printf("Не удалось распарсить: %s\n", f.Name) + return + } + fb2 := reaper.RawToFB2(*rawFB2, f.FileInfo().Name(), &bookcase, f.UncompressedSize64, nil) + // total := atomic.LoadUint64(&totalAddedBooks) + // fmt.Printf("\rpaersed book %s %d", "total", total) + jobChan <- BookJob{FB2: fb2} } } - wg.Wait() }