Skip to content

Commit

Permalink
Do not unnecessarily read JSON files when no formatters are enabled
Browse files Browse the repository at this point in the history
Related to #57.
  • Loading branch information
tvdstaaij committed Dec 18, 2016
1 parent de70e2c commit bd29732
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions telegram-history-dump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bd29732

Please sign in to comment.