Module: LlmCostTracker::Ledger::Store

Defined in:
lib/llm_cost_tracker/ledger/store.rb

Class Method Summary collapse

Class Method Details

.insert(events) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/llm_cost_tracker/ledger/store.rb', line 13

def insert(events)
  events = Array(events)
  return if events.empty?

  LlmCostTracker::Call.transaction do
    rows = events.map { |event| attributes_for(event) }
    call_ids = insert_calls_returning_ids(rows, events)
    insert_line_items(events, call_ids)
    insert_call_tags(events, call_ids)
  end
  Ledger::Rollups.increment_safely!(events) if LlmCostTracker.configuration.cache_rollups
end