comparison pkg/imports/agm.go @ 3193:8329c6d3cf2a

Do not offer an import for review that did not import anything
author Tom Gottfried <tom@intevation.de>
date Wed, 08 May 2019 12:45:21 +0200
parents 928cdc06ff37
children c2b65a549c6f
comparison
equal deleted inserted replaced
3192:cd076b7a2227 3193:8329c6d3cf2a
324 entries := []*agmSummaryEntry{} 324 entries := []*agmSummaryEntry{}
325 325
326 checkedGauges := map[models.Isrs]bool{} 326 checkedGauges := map[models.Isrs]bool{}
327 327
328 lines: 328 lines:
329 for line := 1; ; line++ { 329 for line, ignored := 1, 0; ; line++ {
330 330
331 row, err := r.Read() 331 row, err := r.Read()
332 switch { 332 switch {
333 case err == io.EOF || len(row) == 0: 333 case err == io.EOF || len(row) == 0:
334 if ignored == line-1 {
335 return nil, UnchangedError("No entries imported")
336 }
334 break lines 337 break lines
335 case err != nil: 338 case err != nil:
336 return nil, fmt.Errorf("CSV parsing failed: %v", err) 339 return nil, fmt.Errorf("CSV parsing failed: %v", err)
337 } 340 }
338 341
343 } 346 }
344 347
345 if exists, found := checkedGauges[*gid]; found { 348 if exists, found := checkedGauges[*gid]; found {
346 if !exists { 349 if !exists {
347 // Just ignore the line since we have already warned 350 // Just ignore the line since we have already warned
351 ignored++
348 continue lines 352 continue lines
349 } 353 }
350 } else { // not found in gauge cache 354 } else { // not found in gauge cache
351 if err := gaugeCheckStmt.QueryRowContext( 355 if err := gaugeCheckStmt.QueryRowContext(
352 ctx, 356 ctx,
359 return nil, err 363 return nil, err
360 } 364 }
361 checkedGauges[*gid] = exists 365 checkedGauges[*gid] = exists
362 if !exists { 366 if !exists {
363 feedback.Warn("Ignoring data for unknown gauge %s", gid.String()) 367 feedback.Warn("Ignoring data for unknown gauge %s", gid.String())
368 ignored++
364 continue lines 369 continue lines
365 } 370 }
366 } 371 }
367 372
368 md, err := guessDate(row[measureDateIdx]) 373 md, err := guessDate(row[measureDateIdx])