From bd29732442be49556b72bab1e6df34318617b614 Mon Sep 17 00:00:00 2001 From: Tim van der Staaij Date: Sun, 18 Dec 2016 23:50:11 +0100 Subject: [PATCH] Do not unnecessarily read JSON files when no formatters are enabled Related to #57. --- telegram-history-dump.rb | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/telegram-history-dump.rb b/telegram-history-dump.rb index 73c0c42..d256dc0 100755 --- a/telegram-history-dump.rb +++ b/telegram-history-dump.rb @@ -352,24 +352,26 @@ def save_progress end $dumper.end_backup -$log.info('Formatting messages') unless enabled_formatters.empty? -enabled_formatters.each do |formatter| - formatter.start_backup(backup_list) -end -backup_list.each do |dialog| - dialog_progress = $progress[dialog['id'].to_s] - json_file = File.join(get_backup_dir, dialog_progress.dumper_state['outfile']) - messages = [] - File.open(json_file, 'r:UTF-8').each do |line| - messages.push(JSON.parse(line)) +unless enabled_formatters.empty? + $log.info('Formatting messages') + enabled_formatters.each do |formatter| + formatter.start_backup(backup_list) + end + backup_list.each do |dialog| + dumper_outfile = $progress[dialog['id'].to_s].dumper_state['outfile'] + json_file = File.join(get_backup_dir, dumper_outfile) + messages = [] + File.open(json_file, 'r:UTF-8').each do |line| + messages.push(JSON.parse(line)) + end + enabled_formatters.each do |formatter| + formatter.format_dialog(dialog, messages) + end end enabled_formatters.each do |formatter| - formatter.format_dialog(dialog, messages) + formatter.end_backup end end -enabled_formatters.each do |formatter| - formatter.end_backup -end if cli_opts.kill_tg connect_socket