Skip to content

Conversation

@marcosgz
Copy link
Owner

@marcosgz marcosgz commented Jul 18, 2025

Add update_lazy_attributes command to the CLI to let update a lazy attributes in batches.

Usage

esse index update_lazy_attributes UsersIndex events_count

The collection of index must implement the #each_batch_ids method.

Example:

 class UsersIndex::Collections::UserCollection < Esse::Collection
  def initialize(**context)
    @query = User.preload(:profile)
    @query = @query.where(active: true) if context[:active]
  end

  def each_batch_ids
    query.except(:includes, :preload, :eager_load).in_batches do |batch|
      yield batch.pluck(:id)
    end
  end

  protected

  attr_reader :query
end

@marcosgz marcosgz merged commit fa9d86c into main Jul 18, 2025
17 of 32 checks passed
@marcosgz marcosgz deleted the marcosgz/cli-update-lazy-attrs branch July 18, 2025 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants