Skip to content

Commit

Permalink
Merge pull request #528 from oom-ai/jinghan/fix_join
Browse files Browse the repository at this point in the history
refactor(database/offline): drop tables after row read complete
  • Loading branch information
jinghancc authored Nov 18, 2021
2 parents 91db52b + 589311a commit edcfae0
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions internal/database/offline/postgres/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,15 @@ func (db *DB) readJoinedTable(ctx context.Context, entityRowsTableName string, t
}

data := make(chan []interface{})
var scanErr error
var scanErr, dropErr error
go func() {
defer rows.Close()
defer close(data)
defer func() {
if err := db.dropTemporaryTables(ctx, tableNames); err != nil {
dropErr = err
}
defer rows.Close()
defer close(data)
}()
for rows.Next() {
record, err := rows.SliceScan()
if err != nil {
Expand All @@ -146,10 +151,15 @@ func (db *DB) readJoinedTable(ctx context.Context, entityRowsTableName string, t
data <- record
}
}()

// TODO: return errors through channel
if scanErr != nil {
return nil, scanErr
}
return &types.JoinResult{
Header: header,
Data: data,
}, scanErr
}, dropErr
}

func (db *DB) dropTemporaryTables(ctx context.Context, tableNames []string) error {
Expand Down

0 comments on commit edcfae0

Please sign in to comment.