Koen Van der Auwera avatar Koen Van der Auwera committed 0fc0d36

store revisions in order to know which files are updated

Comments (0)

Files changed (2)

       @tags.split(",").map(&:strip) if @tags
     end
 
+    def self.id_from_filename(filename)
+      File.basename(filename, ".md")
+    end
+
     def self.parse(filename, contents="")
-      post = Post.new(File.basename(filename, ".md"))
+      post = Post.new(id_from_filename(filename))
       contents = contents.force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
       contents.split("\n").each do |line|
         unless head = match_header(post, line)
     end
 
     def self.parse_from_file(filename)
-      post = Post.new(File.basename(filename, ".md"))
+      post = Post.new(id_from_filename(filename))
       IO.readlines(filename).each do |line|
         line = line.force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
         unless head = match_header(post, line)
 
     POST_KEY_PREFIX = "post:"
     POSTS_KEY = "posts"
+    POST_REV_PREFIX = "rev:post:"
     POSTS_LAST_KEY = "posts:last"
     POSTS_RANDOM = "posts:random"
     DROPBOX = "dropbox"
       post(redis.get("posts:last"))
     end
 
+    def changed?(post_id, rev)
+      if stored_rev = redis.get("#{POST_REV_PREFIX}#{post_id}")
+        return stored_rev != rev
+      else
+        redis.set "#{POST_REV_PREFIX}#{post_id}", rev
+        return true
+      end
+    end
+
     def read_posts_from_dropbox
       posts = []
       client = DropboxClient.new(dropbox_session, :app_folder)
-      client.metadata('/')["contents"].map{|f| f["path"]}.select{|f| f =~ /\d{12}\.md$/}.each do |path|
-        contents, meta = client.get_file_and_metadata(path)
-        posts << Post.parse(path, contents)
+      client.metadata('/')["contents"].map{|f| [f["path"], f["rev"]]}.select{|f| f[0] =~ /\d{12}\.md$/}.each do |path|
+        if changed?(Post.id_from_filename(path[0]), path[1])
+          contents, meta = client.get_file_and_metadata(path[0])
+          posts << Post.parse(path[0], contents)
+        end
       end
       posts
     end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.