Skip to content

Instantly share code, notes, and snippets.

@roryfranklin
Created October 7, 2010 10:06
Show Gist options
  • Save roryfranklin/614916 to your computer and use it in GitHub Desktop.
Save roryfranklin/614916 to your computer and use it in GitHub Desktop.
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
@samlown
Copy link

samlown commented Oct 7, 2010

Any chance of including at least part of the model definition?

@roryfranklin
Copy link
Author

Hi Sam,

Sorry, the model definition was in the linked repository, but I've updated the Gist above with the Model definition too.

@samlown
Copy link

samlown commented Oct 7, 2010

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.

@roryfranklin
Copy link
Author

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