From bf542ec12f1c7ca2f275f90d0b8d0a120a07a461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Wed, 21 Apr 2021 10:29:52 +0200 Subject: [PATCH] Fix performance problem on document extraction (#17470) --- services/docextractor/plain.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/services/docextractor/plain.go b/services/docextractor/plain.go index cac6d06e1a..12393e2767 100644 --- a/services/docextractor/plain.go +++ b/services/docextractor/plain.go @@ -20,10 +20,15 @@ func (pe *plainExtractor) Extract(filename string, r io.ReadSeeker) (string, err // This detects any visible character plus any whitespace validRanges := append(unicode.GraphicRanges, unicode.White_Space) - text, _ := ioutil.ReadAll(r) + runes := make([]byte, 1028) + _, err := r.Read(runes) + if err != nil { + return "", err + } + count := 0 for { - c, size := utf8.DecodeRune(text[count:]) + c, size := utf8.DecodeRune(runes[count:]) if !unicode.In(c, validRanges...) { return "", nil } @@ -36,5 +41,6 @@ func (pe *plainExtractor) Extract(filename string, r io.ReadSeeker) (string, err } } + text, _ := ioutil.ReadAll(r) return string(text), nil }