Skip to content

Commit 7aef02d

Browse files
committed
Add index on updatedAt in member schema and start query service on initialization
1 parent ed58163 commit 7aef02d

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

backend/src/database.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class Database {
218218
});
219219
memberSchema.index({ org: 1, login: 1, id: 1 }, { unique: true });
220220
memberSchema.index({ seat: 1 });
221+
memberSchema.index({ updatedAt: -1 });
221222
memberSchema.virtual('seats', {
222223
ref: 'Seats',
223224
localField: '_id',

backend/src/github.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class GitHub {
120120
this.queryService = new QueryService(this.app, {
121121
cronTime: this.cronExpression
122122
});
123+
await this.queryService.start();
123124
logger.info(`CRON task ${this.cronExpression} started`);
124125
}
125126
for await (const { octokit, installation } of this.app.eachInstallation.iterator()) {

backend/src/services/query.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ class QueryService {
3434
...options
3535
}
3636
this.cronJob = CronJob.from(_options);
37-
this.task();
3837
}
3938

4039
delete() {
4140
this.cronJob.stop();
4241
}
4342

43+
start() {
44+
return this.task();
45+
}
46+
4447
private async task() {
4548
const queryAt = new Date();
4649
logger.info(`Task started. Last ran at `, this.cronJob.lastDate());
@@ -76,7 +79,7 @@ class QueryService {
7679
seats: uniqueSeatsArray
7780
}
7881

79-
adoptionService.createAdoption(enterpriseAdoptionData);
82+
await adoptionService.createAdoption(enterpriseAdoptionData);
8083
}
8184

8285
private async orgTask(octokit: Octokit, queryAt: Date, org: string) {

0 commit comments

Comments
 (0)