Skip to content

Commit

Permalink
Reducing the amount of DB lookups for object lists
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Jan 9, 2025
1 parent 7a10a2e commit 7efa895
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,18 @@ public static IHCNode getProcessID (@Nonnull final IDocumentTypeIdentifier aDocT
public static IHCNode getTransportProfile (@Nullable final String sTransportProfile, final boolean bInDetails)
{
final ISMPTransportProfileManager aTransportProfileMgr = SMPMetaManager.getTransportProfileMgr ();

// This may be an SQL query
final ISMPTransportProfile aTP = aTransportProfileMgr.getSMPTransportProfileOfID (sTransportProfile);
final boolean bIsValid = true;
return getTransportProfile (sTransportProfile, aTP, bInDetails);
}

@Nonnull
public static IHCNode getTransportProfile (@Nullable final String sTransportProfile,
@Nullable final ISMPTransportProfile aTP,
final boolean bInDetails)
{
final boolean bIsValid = true;
if (aTP == null)
return _createFormattedID (sTransportProfile, null, null, false, null, null, bInDetails, bIsValid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.phoss.smp.ui;
package com.helger.phoss.smp.ui.cache;

import com.helger.commons.cache.Cache;
import com.helger.phoss.smp.ui.SMPCommonUI;

/**
* Simple owner name cache for Service Group list
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2014-2024 Philip Helger and contributors
* philip[at]helger[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.phoss.smp.ui.cache;

import com.helger.commons.cache.Cache;
import com.helger.peppol.smp.ISMPTransportProfile;
import com.helger.phoss.smp.domain.SMPMetaManager;

/**
* Simple cache for transport profile objects
*
* @author Philip Helger
*/
public final class SMPTransportProfileCache extends Cache <String, ISMPTransportProfile>
{
public SMPTransportProfileCache ()
{
super (x -> SMPMetaManager.getTransportProfileMgr ().getSMPTransportProfileOfID (x), -1, "Transport Profile cache");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager;
import com.helger.phoss.smp.nicename.NiceNameUI;
import com.helger.phoss.smp.rest.SMPRestDataProvider;
import com.helger.phoss.smp.ui.cache.SMPTransportProfileCache;
import com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar;
import com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction;
import com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables;
Expand Down Expand Up @@ -90,6 +91,9 @@ protected void showListOfExistingObjects (@Nonnull final WebPageExecutionContext
EDefaultIcon.MAGNIFIER);
aNodeList.addChild (aToolbar);

// Use the cache here, to avoid too many DB lookups
final SMPTransportProfileCache aTPCache = new SMPTransportProfileCache ();

final HCTable aTable = new HCTable (new DTCol ("Service Group").setInitialSorting (ESortOrder.ASCENDING)
.setDataSort (0, 1, 2, 3),
new DTCol ("Document Type ID").setDataSort (1, 0, 2, 3),
Expand Down Expand Up @@ -118,6 +122,7 @@ protected void showListOfExistingObjects (@Nonnull final WebPageExecutionContext
final String sTransportProfile = aEndpoint.getTransportProfile ();
aRow.addCell (new HCA (createViewURL (aWPEC, CMenuSecure.MENU_TRANSPORT_PROFILES, sTransportProfile))
.addChild (NiceNameUI.getTransportProfile (sTransportProfile,
aTPCache.getFromCache (sTransportProfile),
false)));

final ISimpleURL aEditURL = createEditURL (aWPEC, aServiceInfo).addAll (aParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager;
import com.helger.phoss.smp.nicename.NiceNameUI;
import com.helger.phoss.smp.rest.SMPRestFilter;
import com.helger.phoss.smp.ui.cache.SMPTransportProfileCache;
import com.helger.photon.app.url.LinkHelper;
import com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar;
import com.helger.photon.bootstrap4.table.BootstrapTable;
Expand Down Expand Up @@ -86,6 +87,9 @@ protected void showListOfExistingObjects (@Nonnull final WebPageExecutionContext
aServiceInfoMgr.forEachSMPServiceInformation (x -> aMap.computeIfAbsent (x.getServiceGroupID (),
k -> new CommonsArrayList <> ()).add (x));

// Use the cache here, to avoid too many DB lookups
final SMPTransportProfileCache aTPCache = new SMPTransportProfileCache ();

final HCUL aULSG = new HCUL ();
final ICommonsList <String> aServiceGroupIDs = aServiceGroupMgr.getAllSMPServiceGroupIDs ()
.getSorted (Comparator.naturalOrder ());
Expand Down Expand Up @@ -123,6 +127,7 @@ protected void showListOfExistingObjects (@Nonnull final WebPageExecutionContext
final String sTransportProfile = aEndpoint.getTransportProfile ();
final ISimpleURL aViewURL = createViewURL (aWPEC, aServiceInfo, aParams);
aBodyRow.addCell (new HCA (aViewURL).addChild (NiceNameUI.getTransportProfile (sTransportProfile,
aTPCache.getFromCache (sTransportProfile),
false)));

aBodyRow.addCell (aEndpoint.getEndpointReference ());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
import com.helger.phoss.smp.smlhook.RegistrationHookFactory;
import com.helger.phoss.smp.ui.AbstractSMPWebPageForm;
import com.helger.phoss.smp.ui.SMPCommonUI;
import com.helger.phoss.smp.ui.SMPOwnerNameCache;
import com.helger.phoss.smp.ui.cache.SMPOwnerNameCache;
import com.helger.phoss.smp.ui.secure.hc.HCUserSelect;
import com.helger.photon.app.url.LinkHelper;
import com.helger.photon.bootstrap4.alert.BootstrapQuestionBox;
Expand Down

0 comments on commit 7efa895

Please sign in to comment.