diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2010-10-05 09:35:58 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2010-10-05 09:35:58 -0700 |
commit | 7d98f54e121465da316973019794ce8844658d65 (patch) | |
tree | 63d1a278ff81980ea13919e23f5c3ff55920e1c7 /lognotify.rb | |
parent | 0ff22feb7d33884bdeaac9ad7f6339f3fed4c056 (diff) | |
download | lognotify-7d98f54e121465da316973019794ce8844658d65.tar.gz lognotify-7d98f54e121465da316973019794ce8844658d65.tar.xz |
Faster line count; thanks to awkwood.
Diffstat (limited to 'lognotify.rb')
-rwxr-xr-x | lognotify.rb | 9 |
1 files changed, 8 insertions, 1 deletions
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. |