Added Revision.timestamp attribute, which is a timestamp to the precision of msec. Intention is to get rid of the revision.number and use this one for sotrting etc. The problem with created_at / updated_at in this role is that trhey have precision of seconds, which is not good enough for some of the purposes.

instiki-ar
Alexey Verkhovsky 2005-08-14 18:58:36 +00:00
parent b4ae0b3065
commit 476d7810f6
3 changed files with 19 additions and 2 deletions

View File

@ -112,11 +112,18 @@ class Revision < ActiveRecord::Base
end
protected
before_create :set_revision_number
before_create :set_revision_number, :set_timestamp
after_create :force_rendering
after_save :clear_display_cache
# TODO Refactor this away. Revisions collection should not rely on the revision number for
# sorting etc - revisions must be easy to delete (this helps fighting wiki spam)
def set_revision_number
self.number = self.class.count(['page_id = ?', page_id]) + 1
end
def set_timestamp
self.timestamp = (Time.now.to_f * 1000).to_i.to_s
end
end

View File

@ -2,6 +2,8 @@ CREATE TABLE revisions (
id <%= @pk %>,
created_at <%= @datetime %> NOT NULL,
updated_at <%= @datetime %> NOT NULL,
timestamp CHAR(13) NOT NULL,
page_id INTEGER NOT NULL,
content TEXT NOT NULL,
author VARCHAR(60),

View File

@ -2,6 +2,7 @@ home_page_first_revision:
id: 1
created_at: <%= Time.local(2004, 4, 4, 15, 50).to_formatted_s(:db) %>
updated_at: <%= Time.local(2004, 4, 4, 15, 50).to_formatted_s(:db) %>
timestamp: <%= (Time.local(2004, 4, 4, 15, 50).to_f * 1000).to_i %>
page_id: 1
number: 1
content: First revision of the HomePage end
@ -12,6 +13,7 @@ my_way_first_revision:
id: 2
created_at: <%= 9.days.ago.to_formatted_s(:db) %>
updated_at: <%= 9.days.ago.to_formatted_s(:db) %>
timestamp: <%= (9.days.ago.to_f * 1000).to_i %>
page_id: 2
number: 1
content: MyWay
@ -21,6 +23,7 @@ smart_engine_first_revision:
id: 3
created_at: <%= 8.days.ago.to_formatted_s(:db) %>
updated_at: <%= 8.days.ago.to_formatted_s(:db) %>
timestamp: <%= (8.days.ago.to_f * 1000).to_i %>
page_id: 3
number: 1
content: SmartEngine
@ -30,6 +33,7 @@ that_way_first_revision:
id: 4
created_at: <%= 7.days.ago.to_formatted_s(:db) %>
updated_at: <%= 7.days.ago.to_formatted_s(:db) %>
timestamp: <%= (7.days.ago.to_f * 1000).to_i %>
page_id: 4
number: 1
content: ThatWay
@ -39,6 +43,7 @@ no_wiki_word_first_revision:
id: 5
created_at: <%= 6.days.ago.to_formatted_s(:db) %>
updated_at: <%= 6.days.ago.to_formatted_s(:db) %>
timestamp: <%= (6.days.ago.to_f * 1000).to_i %>
page_id: 5
number: 1
content: hey you
@ -48,6 +53,7 @@ home_page_second_revision:
id: 6
created_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %>
updated_at: <%= Time.local(2004, 4, 4, 16, 50).to_formatted_s(:db) %>
timestamp: <%= (Time.local(2004, 4, 4, 16, 50).to_f * 1000).to_i %>
page_id: 1
number: 2
content: HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \OverThere -- see SmartEngine in that SmartEngineGUI
@ -57,6 +63,7 @@ first_page_first_revision:
id: 7
created_at: <%= Time.local(2004, 4, 4, 16, 55).to_formatted_s(:db) %>
updated_at: <%= Time.local(2004, 4, 4, 16, 55).to_formatted_s(:db) %>
timestamp: <%= (Time.local(2004, 4, 4, 16, 55).to_f * 1000).to_i %>
page_id: 6
number: 1
content: HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- see SmartEngine in that SmartEngineGUI
@ -66,6 +73,7 @@ oak_first_revision:
id: 8
created_at: <%= 5.days.ago.to_formatted_s(:db) %>
updated_at: <%= 5.days.ago.to_formatted_s(:db) %>
timestamp: <%= (5.days.ago.to_f * 1000).to_i %>
page_id: 7
number: 1
content: "All about oak.\ncategory: trees"
@ -76,9 +84,9 @@ elephant_first_revision:
id: 9
created_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
updated_at: <%= 10.minutes.ago.to_formatted_s(:db) %>
timestamp: <%= (10.minutes.ago.to_f * 1000).to_i %>
page_id: 8
number: 1
content: "All about elephants.\ncategory: animals"
author: Guest
ip: 127.0.0.2