refactor: Use limit to prevent fetching all records
This commit is contained in:
@@ -91,6 +91,7 @@ class Flow extends Base {
|
|||||||
async lastInternalId() {
|
async lastInternalId() {
|
||||||
const lastExecution = await this.$relatedQuery('executions')
|
const lastExecution = await this.$relatedQuery('executions')
|
||||||
.orderBy('created_at', 'desc')
|
.orderBy('created_at', 'desc')
|
||||||
|
.limit(1)
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
return lastExecution ? (lastExecution as Execution).internalId : null;
|
return lastExecution ? (lastExecution as Execution).internalId : null;
|
||||||
|
@@ -117,6 +117,7 @@ class Step extends Base {
|
|||||||
async getLastExecutionStep() {
|
async getLastExecutionStep() {
|
||||||
const lastExecutionStep = await this.$relatedQuery('executionSteps')
|
const lastExecutionStep = await this.$relatedQuery('executionSteps')
|
||||||
.orderBy('created_at', 'desc')
|
.orderBy('created_at', 'desc')
|
||||||
|
.limit(1)
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
return lastExecutionStep;
|
return lastExecutionStep;
|
||||||
|
@@ -102,7 +102,7 @@ class User extends Base {
|
|||||||
to: 'users.id',
|
to: 'users.id',
|
||||||
},
|
},
|
||||||
filter(builder: ExtendedQueryBuilder<UsageData>) {
|
filter(builder: ExtendedQueryBuilder<UsageData>) {
|
||||||
builder.orderBy('created_at', 'desc').first();
|
builder.orderBy('created_at', 'desc').limit(1).first();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
subscriptions: {
|
subscriptions: {
|
||||||
@@ -121,7 +121,7 @@ class User extends Base {
|
|||||||
to: 'users.id',
|
to: 'users.id',
|
||||||
},
|
},
|
||||||
filter(builder: ExtendedQueryBuilder<Subscription>) {
|
filter(builder: ExtendedQueryBuilder<Subscription>) {
|
||||||
builder.orderBy('created_at', 'desc').first();
|
builder.orderBy('created_at', 'desc').limit(1).first();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user