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:
parent
3b0b372f75
commit
87fd924be3
@ -91,6 +91,10 @@ export class FeatureToggleRowConverter {
|
||||
enabled: row.enabled || false,
|
||||
};
|
||||
|
||||
if (!newEnvironment.name || !newEnvironment.lastSeenAt) {
|
||||
return;
|
||||
}
|
||||
|
||||
feature.environments.push(newEnvironment);
|
||||
};
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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',
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user