Merge pull request #207 from 67P/feature/optional_full_sync

Make full data sync optional, start via button
This commit was merged in pull request #207.
This commit is contained in:
Râu Cao
2023-01-15 12:36:59 +08:00
committed by GitHub
4 changed files with 48 additions and 6 deletions
+14 -3
View File
@@ -48,6 +48,8 @@ export default Service.extend({
contributionsNeedSync: false,
reimbursementsNeedSync: false,
missingHistoricContributionsCount: 0,
init () {
this._super(...arguments);
this.set('contributors', []);
@@ -230,12 +232,20 @@ export default Service.extend({
await this.loadObjectsFromCache('Contribution');
this.set('contributionsNeedSync', true);
} else {
await this.fetchContributions({ page: { size: 30 } });
await this.fetchContributions({ page: { size: 40 } });
}
await this.updateMissingHistoricContributionsCount();
return Promise.resolve();
},
async updateMissingHistoricContributionsCount () {
const contributionsCount = await this.kredits.Contribution.count;
this.set('missingHistoricContributionsCount', contributionsCount - this.contributions.length);
console.debug(`Missing ${this.missingHistoricContributionsCount} historic contributions (out of ${contributionsCount} overall)`)
},
addContributor (attributes) {
if (attributes.github_uid) {
const uidInt = parseInt(attributes.github_uid);
@@ -371,11 +381,12 @@ export default Service.extend({
syncContributions: task(function * () {
yield this.fetchNewContributions.perform();
yield this.syncUnconfirmedContributions.perform();
yield this.updateMissingHistoricContributionsCount();
this.set('contributionsNeedSync', false);
}).group('contributionTasks'),
fetchNewContributions: task(function * () {
const count = yield this.kredits.Contribution.functions.contributionsCount();
const count = yield this.kredits.Contribution.count;
const lastKnownContributionId = Math.max.apply(null, this.contributions.mapBy('id'));
const toFetch = count - lastKnownContributionId;
@@ -392,7 +403,7 @@ export default Service.extend({
}),
fetchMissingContributions: task(function * () {
const count = yield this.kredits.Contribution.functions.contributionsCount();
const count = yield this.kredits.Contribution.count;
const allIds = [...Array(count+1).keys()];
allIds.shift(); // remove first item, which is 0
const loadedContributions = new Set(this.contributions.mapBy('id'));