ui: update ProductPerformanceProfitability page to enhance table views and tabs management
This commit is contained in:
@@ -676,7 +676,7 @@ func refreshProductPerformanceStockChunked(ctx context.Context, pg *sql.DB, star
|
||||
return 0, err
|
||||
}
|
||||
defer rows.Close()
|
||||
log.Printf("[ProductPerformanceRefresh] stock mssql query returned, postgres chunk insert start")
|
||||
log.Printf("[ProductPerformanceRefresh] stock mssql query returned, postgres chunk upsert start")
|
||||
|
||||
const chunkSize = 5000
|
||||
count := 0
|
||||
@@ -687,11 +687,6 @@ func refreshProductPerformanceStockChunked(ctx context.Context, pg *sql.DB, star
|
||||
return 0, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
copyStmt, err := prepareProductPerformanceStockCopy(ctx, tx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer copyStmt.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var r productPerformanceStockDaily
|
||||
@@ -709,35 +704,21 @@ func refreshProductPerformanceStockChunked(ctx context.Context, pg *sql.DB, star
|
||||
}
|
||||
continue
|
||||
}
|
||||
if _, err := copyStmt.ExecContext(ctx,
|
||||
r.StockDate, r.ProductCode, r.ColorCode, r.YakaKodu, r.StockQty,
|
||||
r.InQty, r.OutQty, r.KpiInQty, r.KpiOutQty, r.SalesMovementQty,
|
||||
r.ProductionInQty, r.PurchaseInQty, r.ConsumptionOutQty, r.CountDiffQty,
|
||||
); err != nil {
|
||||
if err := insertProductPerformanceStock(ctx, tx, r); err != nil {
|
||||
return count, err
|
||||
}
|
||||
count++
|
||||
chunkRows++
|
||||
if chunkRows >= chunkSize {
|
||||
log.Printf("[ProductPerformanceRefresh] stock chunk commit start inserted_rows=%d scanned_rows=%d", count, seen)
|
||||
if _, err := copyStmt.ExecContext(ctx); err != nil {
|
||||
return count, err
|
||||
}
|
||||
if err := copyStmt.Close(); err != nil {
|
||||
return count, err
|
||||
}
|
||||
log.Printf("[ProductPerformanceRefresh] stock chunk commit start upserted_rows=%d scanned_rows=%d", count, seen)
|
||||
if err := tx.Commit(); err != nil {
|
||||
return count, err
|
||||
}
|
||||
log.Printf("[ProductPerformanceRefresh] stock chunk commit done inserted_rows=%d scanned_rows=%d elapsed=%s", count, seen, time.Since(started).Round(time.Second))
|
||||
log.Printf("[ProductPerformanceRefresh] stock chunk commit done upserted_rows=%d scanned_rows=%d elapsed=%s", count, seen, time.Since(started).Round(time.Second))
|
||||
tx, err = pg.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return count, err
|
||||
}
|
||||
copyStmt, err = prepareProductPerformanceStockCopy(ctx, tx)
|
||||
if err != nil {
|
||||
return count, err
|
||||
}
|
||||
chunkRows = 0
|
||||
}
|
||||
}
|
||||
@@ -745,22 +726,15 @@ func refreshProductPerformanceStockChunked(ctx context.Context, pg *sql.DB, star
|
||||
return count, err
|
||||
}
|
||||
if chunkRows > 0 {
|
||||
log.Printf("[ProductPerformanceRefresh] stock final chunk commit start inserted_rows=%d scanned_rows=%d", count, seen)
|
||||
if _, err := copyStmt.ExecContext(ctx); err != nil {
|
||||
return count, err
|
||||
}
|
||||
if err := copyStmt.Close(); err != nil {
|
||||
return count, err
|
||||
}
|
||||
log.Printf("[ProductPerformanceRefresh] stock final chunk commit start upserted_rows=%d scanned_rows=%d", count, seen)
|
||||
if err := tx.Commit(); err != nil {
|
||||
return count, err
|
||||
}
|
||||
log.Printf("[ProductPerformanceRefresh] stock final chunk commit done inserted_rows=%d scanned_rows=%d elapsed=%s", count, seen, time.Since(started).Round(time.Second))
|
||||
log.Printf("[ProductPerformanceRefresh] stock final chunk commit done upserted_rows=%d scanned_rows=%d elapsed=%s", count, seen, time.Since(started).Round(time.Second))
|
||||
} else {
|
||||
_ = copyStmt.Close()
|
||||
_ = tx.Rollback()
|
||||
}
|
||||
log.Printf("[ProductPerformanceRefresh] stock refresh done inserted_rows=%d scanned_rows=%d elapsed=%s", count, seen, time.Since(started).Round(time.Second))
|
||||
log.Printf("[ProductPerformanceRefresh] stock refresh done upserted_rows=%d scanned_rows=%d elapsed=%s", count, seen, time.Since(started).Round(time.Second))
|
||||
return count, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user