From 17b7bf8ec25327165b7667d29a9b66f15bb82762 Mon Sep 17 00:00:00 2001 From: Vladimir Iakovlev Date: Sat, 2 Sep 2017 10:39:22 +0200 Subject: [PATCH] #682: Parse only the last MB of log --- thefuck/const.py | 2 ++ thefuck/output_readers/read_log.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/thefuck/const.py b/thefuck/const.py index 41534982..19128f3d 100644 --- a/thefuck/const.py +++ b/thefuck/const.py @@ -72,4 +72,6 @@ USER_COMMAND_MARK = u'\u200B' * 10 LOG_SIZE = 1000 +LOG_SIZE_IN_BYTES = 1024 * 1024 + DIFF_WITH_ALIAS = 0.5 diff --git a/thefuck/output_readers/read_log.py b/thefuck/output_readers/read_log.py index 7c039fad..11522dba 100644 --- a/thefuck/output_readers/read_log.py +++ b/thefuck/output_readers/read_log.py @@ -54,6 +54,12 @@ def _get_output_lines(script, log_file): return screen.display +def _skip_old_lines(log_file): + size = os.path.getsize(os.environ['THEFUCK_OUTPUT_LOG']) + if size > const.LOG_SIZE_IN_BYTES: + log_file.seek(size - const.LOG_SIZE_IN_BYTES) + + def get_output(script): """Reads script output from log. @@ -76,6 +82,7 @@ def get_output(script): try: with open(os.environ['THEFUCK_OUTPUT_LOG'], 'rb') as log_file: + _skip_old_lines(log_file) lines = _get_output_lines(script, log_file) output = '\n'.join(lines).strip() debug(u'Received output: {}'.format(output))