summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2010-10-05 09:35:58 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2010-10-05 09:35:58 -0700
commit7d98f54e121465da316973019794ce8844658d65 (patch)
tree63d1a278ff81980ea13919e23f5c3ff55920e1c7
parent0ff22feb7d33884bdeaac9ad7f6339f3fed4c056 (diff)
downloadlognotify-7d98f54e121465da316973019794ce8844658d65.tar.gz
lognotify-7d98f54e121465da316973019794ce8844658d65.tar.xz
Faster line count; thanks to awkwood.
-rwxr-xr-xlognotify.rb9
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.