From 3a48e7e033893878c82e478d72585a8daf71abf3 Mon Sep 17 00:00:00 2001 From: dtookey Date: Wed, 15 Jun 2022 13:52:39 -0400 Subject: [PATCH] fixed Account receivables report. Improved MANY insertion times by rolling up large insertions into large generated queries (sorta dangerous) --- src/finance/ar.go | 10 +++++++++- src/mercury.go | 6 +++--- src/sql/update-mercury-arReport.sql | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/finance/ar.go b/src/finance/ar.go index bf3fbf0..21b63b8 100644 --- a/src/finance/ar.go +++ b/src/finance/ar.go @@ -50,6 +50,11 @@ type ( } ) +func (ar arReportInputLine) ToQueryBlock() string { + companyName := strings.ReplaceAll(ar.AccountName, "'", "\\'") + return fmt.Sprintf("('%s',%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,'%s','%s')", companyName, ar.Current, ar.Thirty, ar.Sixty, ar.Ninety, ar.OverNinety, ar.TotalForPeriod, ar.ReportNameInfo.DateString, ar.ReportNameInfo.Region) +} + func GenerateArAgingReport(pathlike string) { connector := &db.ConnectorGeneric{} res := make([]*arReportInputLine, 0, 5000) @@ -65,8 +70,11 @@ func GenerateArAgingReport(pathlike string) { res = append(res, part) } } + + tableWipe := db.NewRunner("create-mercury-arReports-table.sql", db.MercuryDatabaseName) + connector.ExecuteSqlScript(tableWipe) log.Println("Updating database") - db.BulkUpdate[arReportInputLine](connector, "mercury", "update-mercury-arReport.sql", &res, arReportInputLineMappingFunction) + db.BlockUpdate[arReportInputLine](connector, db.MercuryDatabaseName, "update-mercury-arReport.sql", &res) log.Println("Updates finished.") } diff --git a/src/mercury.go b/src/mercury.go index 0d02a9a..4bc8138 100644 --- a/src/mercury.go +++ b/src/mercury.go @@ -12,17 +12,17 @@ import ( func main() { s := time.Now() - //processQBARReport() + processQBARReport() //updateInsightData() - test() + updateTelecom() f := time.Now() log.Println(f.Sub(s).Milliseconds()) } -func test() { +func updateTelecom() { icx := mercury.NewInterconnect() icx.PseudoInit() icx.InsightDBConnector.ExecuteSqlScript(db.NewRunner("create-mercury-telecomVoice-table.sql", db.MercuryDatabaseName)) diff --git a/src/sql/update-mercury-arReport.sql b/src/sql/update-mercury-arReport.sql index 5da41e3..2722518 100644 --- a/src/sql/update-mercury-arReport.sql +++ b/src/sql/update-mercury-arReport.sql @@ -1,2 +1,2 @@ INSERT INTO mercury.ar_aging_report (AccountName, Current, Thirty, Sixty, Ninety, OverNinety, Total_for_Period, DateExported, Region) -VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?); \ No newline at end of file +VALUES %s; \ No newline at end of file