Skip to content

Batching vs all for build_event_occurrences #24

@devilankur18

Description

@devilankur18

Here is the sample code I thinking off for this. Please give your suggestions. This also includes unique occurrences by adding index to db.

  def self.build_event_occurrences
    # build occurrences for all events
    # TODO: only invalid events
    schedulables = self
    # schedulables.each do |schedulable|

    schedulables = schedulables.includes(:schedule)

    schedulables.find_each(batch_size: 100) do |schedulable|
      begin
        schedulable.build_event_occurrences
      rescue ActiveRecord::RecordNotUnique
        # Ignore it
        next
      rescue Exception => ex
        throw ex
      end
    end
  end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions