Class: Feed::Google::ListGenerator

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/feed/google/list_generator.rb

Overview

Loads the sellable catalog for the Google Merchant feed.

The legacy XML product feed generation + GoogleFeed caching were removed when
products moved to the Merchant API push; only load_products remains, reused
by Edi::Google::ProductDataProcessor (same scope + valid_for_google? gate
the XML feed used, so the API push contains exactly the same products).

Constant Summary collapse

BATCH_SIZE =
Feed::Google::ProductBatchLoader::BATCH_SIZE

Instance Method Summary collapse

Instance Method Details

#each_product(catalog, limit: nil, catalog_item_ids: nil, batch_size: BATCH_SIZE) {|presenter| ... } ⇒ Enumerator, void

Yields feed-eligible presenters in bounded batches and disables the query
cache for the traversal. A presenter memoizes its image records, so keeping
a feed-wide presenter array also kept the entire item/image graph alive.

Parameters:

  • catalog (Catalog)
  • limit (Integer, nil) (defaults to: nil)
  • catalog_item_ids (Array<Integer>, nil) (defaults to: nil)
  • batch_size (Integer) (defaults to: BATCH_SIZE)

Yield Parameters:

Returns:

  • (Enumerator, void)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/services/feed/google/list_generator.rb', line 29

def each_product(catalog, limit: nil, catalog_item_ids: nil, batch_size: BATCH_SIZE, &block)
  return enum_for(__method__, catalog, limit:, catalog_item_ids:, batch_size:) unless block

  Feed::Google::ProductBatchLoader.new.each_batch(catalog, limit:, catalog_item_ids:, batch_size:) do |batch|
    batch.records.each do |record|
      presenter = Feed::Google::GoogleProductPresenter.new(
        record,
        nil,
        country_iso: batch.country_iso,
        variant_metadata: batch.[record.try(:item_id)]
      )
      yield(presenter) if presenter.valid_for_google?
    end
  end
end

#load_products(catalog, limit: nil, catalog_item_ids: nil) ⇒ Array<Feed::Google::GoogleProductPresenter>

Returns feed-eligible presenters.

Parameters:

  • catalog (Catalog)
  • limit (Integer, nil) (defaults to: nil)
  • catalog_item_ids (Array<Integer>, nil) (defaults to: nil)

    optional filter to specific items

Returns:



16
17
18
# File 'app/services/feed/google/list_generator.rb', line 16

def load_products(catalog, limit: nil, catalog_item_ids: nil)
  each_product(catalog, limit:, catalog_item_ids:).to_a
end