1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

refactor: optimize queries (#5158)

This commit will change the join to only get results for either archived
or non-archived features based on the query
This commit is contained in:
Fredrik Strand Oseberg 2023-10-26 13:38:22 +02:00 committed by GitHub
parent 3b0b372f75
commit 87fd924be3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 5 deletions

View File

@ -91,6 +91,10 @@ export class FeatureToggleRowConverter {
enabled: row.enabled || false,
};
if (!newEnvironment.name || !newEnvironment.lastSeenAt) {
return;
}
feature.environments.push(newEnvironment);
};

View File

@ -172,7 +172,7 @@ export default class FeatureToggleStore implements IFeatureToggleStore {
builder.addSelectColumn('ft.tag_type as tag_type');
if (this.flagResolver.isEnabled('useLastSeenRefactor')) {
builder.withLastSeenByEnvironment();
builder.withLastSeenByEnvironment(archived);
builder.addSelectColumn(
'last_seen_at_metrics.last_seen_at as env_last_seen_at',
);
@ -262,7 +262,8 @@ export default class FeatureToggleStore implements IFeatureToggleStore {
'features.archived_at as archived_at',
]);
builder.query('features').withLastSeenByEnvironment();
const archived = true;
builder.query('features').withLastSeenByEnvironment(archived);
builder.addSelectColumn(
'last_seen_at_metrics.last_seen_at as env_last_seen_at',

View File

@ -176,7 +176,7 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
flagResolver: IFlagResolver,
) {
this.db = db;
this.logger = getLogger('feature-toggle-store.ts');
this.logger = getLogger('feature-toggle-strategies-store.ts');
this.timer = (action) =>
metricsHelper.wrapTimer(eventBus, DB_TIME, {
store: 'feature-toggle-strategies',

View File

@ -93,8 +93,16 @@ export class FeatureToggleListBuilder {
return this;
}
withLastSeenByEnvironment = () => {
this.internalQuery.leftJoin('last_seen_at_metrics', 'last_seen_at_metrics.feature_name', 'features.name');
withLastSeenByEnvironment = (archived = false) => {
if (archived) {
this.internalQuery.leftJoin('last_seen_at_metrics', function() {
this.on('last_seen_at_metrics.feature_name', '=', 'features.name')
.andOnNotNull('features.archived_at');
})
} else {
this.internalQuery.leftJoin('last_seen_at_metrics', 'last_seen_at_metrics.feature_name', 'features.name');
}
return this;
}