whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] branch master updated: move agenda cache from IPC to locked files on disk
Date Fri, 07 Oct 2016 18:00:09 GMT
This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/whimsy.git

The following commit(s) were added to refs/heads/master by this push:
       new  9c6648f   move agenda cache from IPC to locked files on disk
9c6648f is described below

commit 9c6648ff5f309467c0112179292f4c50d8b2035a
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Fri Oct 7 13:58:45 2016 -0400

    move agenda cache from IPC to locked files on disk
---
 www/board/agenda/main.rb             |  3 ++-
 www/board/agenda/models/agenda.rb    | 29 +++++++++++++++++++++++++----
 www/board/agenda/spec/spec_helper.rb |  5 +++++
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/www/board/agenda/main.rb b/www/board/agenda/main.rb
index eec8498..2cf62c3 100755
--- a/www/board/agenda/main.rb
+++ b/www/board/agenda/main.rb
@@ -29,9 +29,10 @@ else
   AGENDA_WORK = ASF::Config.get(:agenda_work).untaint || '/srv/agenda'
   STDERR.puts "* SVN board  : #{FOUNDATION_BOARD}"
   STDERR.puts "* Agenda work: #{AGENDA_WORK}"
-  FileUtils.mkdir_p AGENDA_WORK if not Dir.exist? AGENDA_WORK
 end
 
+FileUtils.mkdir_p AGENDA_WORK if not Dir.exist? AGENDA_WORK
+
 require_relative './routes'
 require_relative './models/ipc'
 require_relative './models/pending'
diff --git a/www/board/agenda/models/agenda.rb b/www/board/agenda/models/agenda.rb
index 0df47e3..2d0e6af 100755
--- a/www/board/agenda/models/agenda.rb
+++ b/www/board/agenda/models/agenda.rb
@@ -10,12 +10,33 @@
 require 'digest'
 
 class Agenda
+  CACHE = File.join(AGENDA_WORK, 'cache')
+  FileUtils.mkdir_p CACHE
+
   def self.[](file)
-    IPC[file]
+    path = File.join(CACHE, file.sub(/\.txt$/, '.yml'))
+    path.untaint if file =~ /^board_agenda_\d+_\d+_\d+\.txt$/
+    data = if File.exist? path
+      File.open(path) do |file|
+        file.flock(File::LOCK_SH)
+        YAML.load(file.read) || {mtime: 0}
+      end
+    else
+      {mtime: 0}
+    end
+
   end
 
   def self.[]=(file, data)
-    IPC[file] = data
+    path = File.join(CACHE, file.sub(/\.txt$/, '.yml'))
+    path.untaint if file =~ /^board_agenda_\d+_\d+_\d+\.txt$/
+    File.open(path, File::RDWR|File::CREAT, 0644) do |file|
+      file.flock(File::LOCK_EX)
+      file.write(YAML.dump(data))
+      file.flush
+      file.truncate(file.pos)
+    end
+    data
   end
 
   def self.update_cache(file, path, contents, quick)
@@ -27,11 +48,11 @@ class Agenda
 
     # update cache if there wasn't a previous entry, the digest changed,
     # or the previous entry was the result of a 'quick' parse.
-    current = IPC[file]
+    current = Agenda[file]
     if not current or current[:digest] != update[:digest] or
       current[:mtime].to_i <= 0
     then
-      IPC[file] = update
+      Agenda[file] = update
       IPC.post type: :agenda, file: file, digest: update[:digest] unless quick
     end
   end
diff --git a/www/board/agenda/spec/spec_helper.rb b/www/board/agenda/spec/spec_helper.rb
index e8dcc20..f5e6ea5 100644
--- a/www/board/agenda/spec/spec_helper.rb
+++ b/www/board/agenda/spec/spec_helper.rb
@@ -66,4 +66,9 @@ end
 
 RSpec.configure do |config|
   config.include MockServer
+
+  config.before(:each) do
+    FileUtils.rm_rf Agenda::CACHE
+    FileUtils.mkdir_p Agenda::CACHE
+  end
 end

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <commits@whimsical.apache.org>'].

Mime
View raw message