changeset 5561:b91716d2acc6

Fixed log message analyzing in log export.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 11 Feb 2022 18:57:11 +0100
parents f2204f91d286
children 5152b4db40cc
files pkg/controllers/importqueue.go pkg/imports/sr.go
diffstat 2 files changed, 16 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/importqueue.go	Wed Feb 09 18:34:40 2022 +0100
+++ b/pkg/controllers/importqueue.go	Fri Feb 11 18:57:11 2022 +0100
@@ -26,6 +26,7 @@
 	"time"
 
 	"github.com/gorilla/mux"
+	"github.com/jackc/pgx/pgtype"
 
 	"gemma.intevation.de/gemma/pkg/auth"
 	"gemma.intevation.de/gemma/pkg/common"
@@ -71,11 +72,10 @@
     WHERE lu.username = import.imports.username) AS country,
   signer,
   EXISTS(SELECT 1 FROM import.import_logs
-    WHERE kind = 'warn'::log_type and import_id = imports.id) AS has_warnings,
+    WHERE kind = 'warn'::log_type and import_id = id) AS has_warnings,
   data,
-  il.msg
-FROM import.imports RIGHT JOIN import.import_logs il
-  ON import.imports.id = il.import_id
+  ARRAY(SELECT msg FROM import.import_logs WHERE import_id = id) AS msgs
+FROM import.imports
 WHERE
 `
 	selectEnqueuedSQL = `
@@ -367,14 +367,12 @@
 		return out.Write(record)
 	}
 
-	var last *dataset
-
 	for rows.Next() {
 		var (
 			curr dataset
-			msg  sql.NullString
+			msgs pgtype.TextArray
 		)
-		if err = rows.Scan(
+		if err := rows.Scan(
 			&curr.id,
 			&curr.state,
 			&curr.enqueued,
@@ -385,31 +383,23 @@
 			&curr.signer,
 			&curr.warnings,
 			&curr.data,
-			&msg,
+			&msgs,
 		); err != nil {
+			log.Errorf("%v\n", err)
 			return
 		}
 
-		if last != nil && last.id == curr.id {
-			if msg.Valid {
-				last.msgs = append(last.msgs, msg.String)
+		if msgs.Status == pgtype.Present {
+			if err := msgs.AssignTo(&curr.msgs); err != nil {
+				log.Errorf("%v\n", err)
+				return
 			}
-			continue
-		}
-		if msg.Valid {
-			curr.msgs = append(curr.msgs, msg.String)
 		}
 
-		if err := store(last); err != nil {
+		if err := store(&curr); err != nil {
 			log.Errorf("%v\n", err)
 			return
 		}
-		last = &curr
-	}
-
-	if err := store(last); err != nil {
-		log.Errorf("%v\n", err)
-		return
 	}
 
 	out.Flush()
--- a/pkg/imports/sr.go	Wed Feb 09 18:34:40 2022 +0100
+++ b/pkg/imports/sr.go	Fri Feb 11 18:57:11 2022 +0100
@@ -253,8 +253,8 @@
 func compileRecoverRegs() {
 	bottleneckRe = regexp.MustCompile(`Bottleneck:\s*(.+)\s*$`)
 	surveyTypeRe = regexp.MustCompile(`Processing as\s+([^\s]+)\s+beam scan.`)
-	dateRe = regexp.MustCompile(`Survey date:\s*(\d{4}-\d{2}-\d{2}).`)
-	negateZRe = regexp.MustCompile(`Z values will be negated.`)
+	dateRe = regexp.MustCompile(`Survey date:\s*(\d{4}-\d{2}-\d{2})`)
+	negateZRe = regexp.MustCompile(`Z values will be negated\.`)
 }
 
 // Description gives a short info about relevant facts of this import.
@@ -305,6 +305,7 @@
 	}
 
 	if sr.NegateZ != nil && *sr.NegateZ {
+		descs = append(descs, "negateZ")
 	} else if negZ != nil && *negZ {
 		log.Debugln("negateZ recovered")
 		descs = append(descs, "negateZ")