Created
October 7, 2010 10:06
-
-
Save roryfranklin/614916 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Event < CouchRest::Model::Base | |
use_database DB | |
property :event_type, :type => String | |
property :actioner_id, :type => String | |
property :event_date, :type => String | |
property :event_parent, :type => String | |
property :event_hierarchy, :type => [String], :default => [] | |
property :old_state | |
property :new_state | |
view_by :event_date | |
view_by :event_parent | |
validates_presence_of :event_type | |
validates_presence_of :event_date | |
before_save :convert_date | |
def linked_events | |
events = Event.by_event_parent(:key => self.id) | |
end | |
def is_linked? | |
!self.event_parent.blank? | |
end | |
def parent | |
parent_event = Event.get(self.event_parent) | |
parent_event | |
end | |
private | |
def convert_date | |
self.event_date = Time.parse(event_date.to_s) | |
end | |
end | |
(1..100).each do |i| | |
Event.create!(:event_type => "CREATE_PARTITION_#{i}", :event_date => Time.now) | |
end |
Hi Sam,
Sorry, the model definition was in the linked repository, but I've updated the Gist above with the Model definition too.
Not run any tests yet, but I do know for a fact that Time.parse is legendary for its slowness. Try removing that to see if there is any change in performance.
The Time.parse part is only on a save, so that shouldn't affect the speed when loading in a list of documents. Any suggestions on how to standardize dates instead?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any chance of including at least part of the model definition?