Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/kaui/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Kaui
class AccountsController < Kaui::EngineController
def index
@search_query = params[:q]
@advance_search_query = @search_query || request.query_string
@advance_search_query = @search_query.presence || params[:advance_search_query].presence
if @search_query.present?
account = Kaui::Account.list_or_search(@search_query, -1, 1, options_for_klient).first
if account.nil?
Expand Down
11 changes: 9 additions & 2 deletions app/controllers/kaui/bundles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,15 @@ def index
@available_tags = wait(fetch_available_tags)
@available_subscription_tags = wait(fetch_available_subscription_tags)

# Don't load the full catalog to avoid memory issues
@catalog = nil
# Collect the distinct start dates from subscriptions on this page, then fetch
# only the catalog versions needed — one per unique date — to avoid loading all
# historical versions into memory.
start_dates = @bundles.flat_map(&:subscriptions).filter_map(&:start_date).uniq
@catalogs = start_dates.filter_map do |date|
Kaui::Catalog.get_account_catalog_json(@account.account_id, date, cached_options_for_klient)&.last
rescue StandardError
nil
end.uniq(&:effective_date)

@subscription = {}
@bundles.each do |bundle|
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/kaui/engine_controller_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def as_string(exception)
as_string(exception.cause)
else
log_rescue_error(exception)
exception.message
exception.message.to_s[0..200]
end
end

Expand All @@ -150,7 +150,7 @@ def as_string_from_response(response)
error_message += " (code=#{error_message['code']})" if error_message['code'].present?
end
# Limit the error size to avoid ActionDispatch::Cookies::CookieOverflow
error_message[0..1000]
error_message.to_s[0..200]
end

def nested_hash_value(obj, key)
Expand Down
8 changes: 3 additions & 5 deletions app/helpers/kaui/plugin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ def plugin_repository
def installed_plugin_names
plugins = []
nodes_info = KillBillClient::Model::NodesInfo.nodes_info(Kaui.current_tenant_user_options(current_user, session)) || []
plugins_info = nodes_info.empty? ? [] : (nodes_info.first.plugins_info || [])
plugins_info.each do |plugin|
next unless plugin.state == 'RUNNING'

plugins_info = nodes_info.flat_map { |node| node.plugins_info || [] }
plugins_info.select { |p| p.state == 'RUNNING' }.uniq(&:plugin_name).each do |plugin|
plugin_name = plugin.plugin_name
plugin_key = plugin_name.gsub('-plugin', '')

Expand All @@ -40,7 +38,7 @@ def installed_plugin_names
def installed_plugins
installed_plugins = []
nodes_info = KillBillClient::Model::NodesInfo.nodes_info(Kaui.current_tenant_user_options(current_user, session)) || []
plugins_info = nodes_info.empty? ? [] : (nodes_info.first.plugins_info || [])
plugins_info = nodes_info.flat_map { |node| node.plugins_info || [] }

plugins_info.each do |plugin|
next if plugin.version.nil?
Expand Down
18 changes: 18 additions & 0 deletions app/helpers/kaui/subscription_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ def humanized_price_override(sub, separation = ', ', open_bracket = '', close_br
end
end

def catalog_for_subscription(sub, catalogs)
return nil if catalogs.blank? || sub&.start_date.blank?

start_date = Date.parse(sub.start_date)

# Find the latest catalog version whose effective_date <= subscription start_date
best = catalogs.select do |c|
Date.parse(c.effective_date) <= start_date
rescue StandardError
false
end.max_by(&:effective_date)

# Fall back to the oldest version if none precedes the start_date
best || catalogs.first
rescue StandardError
catalogs.last
end

def humanized_subscription_phase_type(sub)
sub.phase_type
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/kaui/bundles/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
<% @bundles.each_with_index do |bundle, idx| %>
<div class="row">
<div class="d-flex">
<%= render :partial => Kaui.bundle_details_partial, :locals => { :bundle => bundle, :account => @account, :catalog => @catalog } %>
<%= render :partial => Kaui.bundle_details_partial, :locals => { :bundle => bundle, :account => @account, :catalog => @catalogs&.last } %>
</div>
<% if bundle.subscriptions.present? %>
<div class="search">
<%= render :partial => 'kaui/subscriptions/subscriptions_table', :locals => {:bundle => bundle, :account => @account, :catalog => @catalog} %>
<%= render :partial => 'kaui/subscriptions/subscriptions_table', :locals => {:bundle => bundle, :account => @account, :catalogs => @catalogs} %>
</div>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/kaui/subscriptions/_subscriptions_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
</div>
</td>
<% end %>
<td><%= humanized_subscription_plan_or_product_name(sub, catalog) %></td>
<td><%= humanized_subscription_plan_or_product_name(sub, catalog_for_subscription(sub, catalogs)) %></td>
<td>
<span id="<%= sub.subscription_id %>-popover" class="object-id-popover category-bedge" data-id="<%= sub.subscription_id %>">
<%= humanized_subscription_product_category(sub) %>
Expand Down
Loading