mirror of
https://github.com/ddworken/hishtory.git
synced 2025-01-23 06:38:52 +01:00
Add check so that if there are zero leftover entries, we don't try to import them into the DB since this leads to install errors
This commit is contained in:
parent
7ffe5fc1e2
commit
717cf2c4b0
@ -327,7 +327,10 @@ func ImportHistory(ctx context.Context, shouldReadStdin, force bool) (int, error
|
||||
batch = append(batch, entry)
|
||||
if len(batch) > batchSize {
|
||||
err = RetryingDbFunction(func() error {
|
||||
return db.Create(batch).Error
|
||||
if err := db.Create(batch).Error; err != nil {
|
||||
return fmt.Errorf("failed to import batch of history entries: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
iteratorError = fmt.Errorf("failed to insert imported history entry: %w", err)
|
||||
@ -342,9 +345,14 @@ func ImportHistory(ctx context.Context, shouldReadStdin, force bool) (int, error
|
||||
return 0, iteratorError
|
||||
}
|
||||
// Also create any entries remaining in an unfinished batch
|
||||
err = RetryingDbFunction(func() error {
|
||||
return db.Create(batch).Error
|
||||
})
|
||||
if len(batch) > 0 {
|
||||
err = RetryingDbFunction(func() error {
|
||||
if err := db.Create(batch).Error; err != nil {
|
||||
return fmt.Errorf("failed to import final batch of history entries: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user