Skip to content

Commit

Permalink
LPD-37834 Avoid the table join DSL. Initiate the query from SegmentsE…
Browse files Browse the repository at this point in the history
…xperimentRel and post filtering by checking SegmentsExperiment's groupId and plid. This is a redo for 979b481
  • Loading branch information
shuyangzhou authored and brianchandotcom committed Oct 1, 2024
1 parent 1d09932 commit 9861764
Showing 1 changed file with 18 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package com.liferay.segments.service.impl;

import com.liferay.petra.sql.dsl.DSLQueryFactoryUtil;
import com.liferay.petra.string.StringBundler;
import com.liferay.portal.aop.AopService;
import com.liferay.portal.kernel.dao.orm.DynamicQuery;
Expand Down Expand Up @@ -50,12 +49,11 @@
import com.liferay.segments.model.SegmentsExperience;
import com.liferay.segments.model.SegmentsExperiment;
import com.liferay.segments.model.SegmentsExperimentRel;
import com.liferay.segments.model.SegmentsExperimentRelTable;
import com.liferay.segments.model.SegmentsExperimentTable;
import com.liferay.segments.service.SegmentsExperienceLocalService;
import com.liferay.segments.service.SegmentsExperimentRelLocalService;
import com.liferay.segments.service.base.SegmentsExperimentLocalServiceBaseImpl;
import com.liferay.segments.service.persistence.SegmentsExperiencePersistence;
import com.liferay.segments.service.persistence.SegmentsExperimentRelPersistence;

import java.math.RoundingMode;

Expand Down Expand Up @@ -209,31 +207,22 @@ public SegmentsExperiment deleteSegmentsExperiment(
public SegmentsExperiment fetchSegmentsExperiment(
long groupId, long segmentsExperienceId, long plid) {

List<SegmentsExperiment> segmentsExperiments =
segmentsExperimentPersistence.dslQuery(
DSLQueryFactoryUtil.select(
SegmentsExperimentTable.INSTANCE
).from(
SegmentsExperimentTable.INSTANCE
).innerJoinON(
SegmentsExperimentRelTable.INSTANCE,
SegmentsExperimentRelTable.INSTANCE.segmentsExperimentId.eq(
SegmentsExperimentTable.INSTANCE.segmentsExperimentId)
).where(
SegmentsExperimentRelTable.INSTANCE.segmentsExperienceId.eq(
segmentsExperienceId
).and(
SegmentsExperimentTable.INSTANCE.groupId.eq(groupId)
).and(
SegmentsExperimentTable.INSTANCE.plid.eq(plid)
)
));

if (segmentsExperiments.isEmpty()) {
return null;
for (SegmentsExperimentRel segmentsExperimentRel :
_segmentsExperimentRelPersistence.findBySegmentsExperienceId(
segmentsExperienceId)) {

SegmentsExperiment segmentsExperiment =
segmentsExperimentPersistence.fetchByPrimaryKey(
segmentsExperimentRel.getSegmentsExperimentId());

if ((segmentsExperiment.getGroupId() == groupId) &&
(segmentsExperiment.getPlid() == plid)) {

return segmentsExperiment;
}
}

return segmentsExperiments.get(0);
return null;
}

@Override
Expand Down Expand Up @@ -722,6 +711,9 @@ private void _validateType(String type) throws PortalException {
private SegmentsExperimentRelLocalService
_segmentsExperimentRelLocalService;

@Reference
private SegmentsExperimentRelPersistence _segmentsExperimentRelPersistence;

@Reference
private UserLocalService _userLocalService;

Expand Down

0 comments on commit 9861764

Please sign in to comment.