Skip to content

Commit

Permalink
Merge pull request #2034 from CarnegieLearningWeb/bugfix/fixing-pagin…
Browse files Browse the repository at this point in the history
…ated-query-2018

Bugfix/fixing paginated query 2018
  • Loading branch information
ppratikcr7 authored Oct 9, 2024
2 parents e7bb64f + 6ccf80b commit 27afa72
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download all workflow run artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4.1.7
- uses: ncipollo/release-action@v1
with:
artifacts: "**/upgrade-*.zip"
Expand Down
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ab_testing_backend",
"version": "6.0.0-prerelease.1",
"version": "6.0.0-prerelease.2",
"description": "Backend for A/B Testing Project",
"scripts": {
"install:all": "npm ci && cd packages/Scheduler && npm ci && cd ../Upgrade && npm ci",
Expand Down
2 changes: 1 addition & 1 deletion backend/packages/Scheduler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ppl-upgrade-serverless",
"version": "6.0.0-prerelease.1",
"version": "6.0.0-prerelease.2",
"description": "Serverless webpack example using Typescript",
"main": "handler.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion backend/packages/Upgrade/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ab_testing_backend",
"version": "6.0.0-prerelease.1",
"version": "6.0.0-prerelease.2",
"description": "Backend for A/B Testing Project",
"main": "index.js",
"scripts": {
Expand Down
36 changes: 30 additions & 6 deletions backend/packages/Upgrade/src/api/services/FeatureFlagService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class FeatureFlagService {
return this.featureFlagRepository.count();
}

public findPaginated(
public async findPaginated(
skip: number,
take: number,
logger: UpgradeLogger,
Expand All @@ -172,10 +172,7 @@ export class FeatureFlagService {
): Promise<FeatureFlag[]> {
logger.info({ message: 'Find paginated Feature flags' });

let queryBuilder = this.featureFlagRepository
.createQueryBuilder('feature_flag')
.leftJoinAndSelect('feature_flag.featureFlagSegmentInclusion', 'featureFlagSegmentInclusion')
.loadRelationCountAndMap('feature_flag.featureFlagExposures', 'feature_flag.featureFlagExposures');
let queryBuilder = this.featureFlagRepository.createQueryBuilder('feature_flag');
if (searchParams) {
const customSearchString = searchParams.string.split(' ').join(`:*&`);
// add search query
Expand All @@ -194,7 +191,34 @@ export class FeatureFlagService {
// TODO: the type of queryBuilder.getMany() is Promise<FeatureFlag[]>
// However, the above query returns Promise<(Omit<FeatureFlag, 'featureFlagExposures'> & { featureFlagExposures: number })[]>
// This can be fixed by using a @VirtualColumn in the FeatureFlag entity, when we are on TypeORM 0.3
return queryBuilder.getMany();
const featureFlagsWithExposures = await queryBuilder
.loadRelationCountAndMap('feature_flag.featureFlagExposures', 'feature_flag.featureFlagExposures')
.getMany();

// Get the feature flag ids
const featureFlagIds = featureFlagsWithExposures.map(({ id }) => id);

// Get the relevant segment inclusion documents
const featureFlagWithInclusionSegments = await this.featureFlagRepository.find({
select: ['id', 'featureFlagSegmentInclusion'],
where: { id: In(featureFlagIds) },
relations: ['featureFlagSegmentInclusion'],
});

// Add the inclusion documents to the featureFlagsWithExposures
return featureFlagsWithExposures.map((featureFlag) => {
// Find the matching featureFlagSegmentInclusion for the current item
const inclusionSegment = featureFlagWithInclusionSegments.find(
({ id }) => id === featureFlag.id
)?.featureFlagSegmentInclusion;

// Construct the new object with conditional properties
return {
...featureFlag,
// Only include featureFlagSegmentInclusion if inclusionSegment is defined and not empty
...(inclusionSegment && inclusionSegment.length > 0 ? { featureFlagSegmentInclusion: inclusionSegment } : {}),
};
});
}

public async delete(
Expand Down
2 changes: 1 addition & 1 deletion clientlibs/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
at the same time that happen to rev to the same new version will be caught
by a merge conflict. -->

<version>6.0.0-prelease.0-prerelease.1</version>
<version>6.0.0-prelease.0-prerelease.2</version>
<build>
<plugins>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion clientlibs/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "upgrade_client_lib",
"version": "6.0.0-prerelease.1",
"version": "6.0.0-prerelease.2",
"description": "Client library to communicate with the Upgrade server",
"files": [
"dist/*"
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ab-testing",
"version": "6.0.0-prerelease.1",
"version": "6.0.0-prerelease.2",
"license": "MIT",
"scripts": {
"ng": "ng",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "UpGrade",
"version": "6.0.0-prerelease.1",
"version": "6.0.0-prerelease.2",
"description": "This is a combined repository for UpGrade, an open-source platform to support large-scale A/B testing in educational applications. Learn more at www.upgradeplatform.org",
"main": "index.js",
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "upgrade_types",
"version": "6.0.0-prerelease.1",
"version": "6.0.0-prerelease.2",
"description": "",
"main": "src/index.ts",
"types": "src/index.ts",
Expand Down

0 comments on commit 27afa72

Please sign in to comment.