Skip to content

Commit

Permalink
Optimize performance by removing redundant code not leading to any ou…
Browse files Browse the repository at this point in the history
…tcome
  • Loading branch information
vlaskhilkevich committed Mar 1, 2024
1 parent db9f62a commit 89baaee
Showing 1 changed file with 0 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@

import java.sql.SQLException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

import org.killbill.billing.ObjectType;
import org.killbill.billing.account.api.Account;
import org.killbill.billing.catalog.api.CatalogApiException;
import org.killbill.billing.catalog.api.Plan;
import org.killbill.billing.catalog.api.StaticCatalog;
import org.killbill.billing.invoice.api.Invoice;
import org.killbill.billing.invoice.api.InvoiceItem;
import org.killbill.billing.invoice.plugin.api.InvoiceContext;
Expand Down Expand Up @@ -134,7 +129,6 @@ public OnSuccessInvoiceResult onSuccessCall(final InvoiceContext context, final

private void checkForTaxCodes(final Invoice invoice, final Collection<PluginProperty> properties, final TenantContext context) {
checkForTaxCodesInCustomFields(invoice, properties, context);
checkForTaxCodesOnProducts(invoice, properties, context);
}

private void checkForTaxCodesInCustomFields(final Invoice invoice, final Collection<PluginProperty> properties, final TenantContext context) {
Expand All @@ -159,37 +153,6 @@ private void checkForTaxCodesInCustomFields(final Invoice invoice, final Collect
}
}

private void checkForTaxCodesOnProducts(final Invoice invoice, final Collection<PluginProperty> properties, final TenantContext context) {
final Map<String, String> planToProductCache = new HashMap<>();
final Map<String, String> productToTaxCodeCache = new HashMap<>();

for (final InvoiceItem invoiceItem : invoice.getInvoiceItems()) {
final String planName = invoiceItem.getPlanName();
if (planName == null) {
continue;
}

if (planToProductCache.get(planName) == null) {
try {
final StaticCatalog catalog = killbillAPI.getCatalogUserApi().getCurrentCatalog(null, context);
final Plan plan = catalog.findPlan(planName);
planToProductCache.put(planName, plan.getProduct().getName());
} catch (final CatalogApiException e) {
continue;
}
}
final String productName = planToProductCache.get(planName);
if (productName == null) {
continue;
}

final String taxCode = productToTaxCodeCache.get(productName);
if (taxCode != null) {
addTaxCodeToInvoiceItem(invoiceItem.getId(), productToTaxCodeCache.get(productName), properties);
}
}
}

private void addTaxCodeToInvoiceItem(final UUID invoiceItemId, final String taxCode, final Collection<PluginProperty> properties) {
final String pluginPropertyName = String.format("%s_%s", VertexTaxCalculator.TAX_CODE, invoiceItemId);
// Already in plugin properties?
Expand Down

0 comments on commit 89baaee

Please sign in to comment.