From 7d98f54e121465da316973019794ce8844658d65 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 5 Oct 2010 09:35:58 -0700 Subject: Faster line count; thanks to awkwood. --- lognotify.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lognotify.rb b/lognotify.rb index 6a1430b..8ec2a10 100755 --- a/lognotify.rb +++ b/lognotify.rb @@ -77,9 +77,16 @@ end # Count lines in cached log. def count_lines identifier + count = 0 + File.open(identifier.to_cache_path) do |file| - return file.readlines.length + # Process lines block-by-block to keep memory usage low. + while block = file.read(1024) + count += block.count("\n") + end end + + return count end # Retrieve new lines via SSH. -- cgit v1.2.3-70-g09d2