mirror of
https://github.com/pressly/goose.git
synced 2025-04-27 21:23:39 +00:00
Merge pull request #93 from hexdigest/master
fix goose memory consumption on large migrations
This commit is contained in:
commit
9292c394c8
@ -8,16 +8,27 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
const sqlCmdPrefix = "-- +goose "
|
const sqlCmdPrefix = "-- +goose "
|
||||||
|
const scanBufSize = 4 * 1024 * 1024
|
||||||
|
|
||||||
|
var bufferPool = sync.Pool{
|
||||||
|
New: func() interface{} {
|
||||||
|
return make([]byte, scanBufSize)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// Checks the line to see if the line has a statement-ending semicolon
|
// Checks the line to see if the line has a statement-ending semicolon
|
||||||
// or if the line contains a double-dash comment.
|
// or if the line contains a double-dash comment.
|
||||||
func endsWithSemicolon(line string) bool {
|
func endsWithSemicolon(line string) bool {
|
||||||
|
scanBuf := bufferPool.Get().([]byte)
|
||||||
|
defer bufferPool.Put(scanBuf)
|
||||||
|
|
||||||
prev := ""
|
prev := ""
|
||||||
scanner := bufio.NewScanner(strings.NewReader(line))
|
scanner := bufio.NewScanner(strings.NewReader(line))
|
||||||
|
scanner.Buffer(scanBuf, scanBufSize)
|
||||||
scanner.Split(bufio.ScanWords)
|
scanner.Split(bufio.ScanWords)
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
@ -42,7 +53,11 @@ func endsWithSemicolon(line string) bool {
|
|||||||
// tell us to ignore semicolons.
|
// tell us to ignore semicolons.
|
||||||
func getSQLStatements(r io.Reader, direction bool) ([]string, bool, error) {
|
func getSQLStatements(r io.Reader, direction bool) ([]string, bool, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
scanBuf := bufferPool.Get().([]byte)
|
||||||
|
defer bufferPool.Put(scanBuf)
|
||||||
|
|
||||||
scanner := bufio.NewScanner(r)
|
scanner := bufio.NewScanner(r)
|
||||||
|
scanner.Buffer(scanBuf, scanBufSize)
|
||||||
|
|
||||||
// track the count of each section
|
// track the count of each section
|
||||||
// so we can diagnose scripts with no annotations
|
// so we can diagnose scripts with no annotations
|
||||||
|
Loading…
x
Reference in New Issue
Block a user