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
+3 -1
View File
@@ -1,6 +1,6 @@
import Controller from '@ember/controller'; import Controller from '@ember/controller';
import { computed } from '@ember/object'; import { computed } from '@ember/object';
import { alias, not, sort } from '@ember/object/computed'; import { alias, gt, not, sort } from '@ember/object/computed';
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
export default Controller.extend({ export default Controller.extend({
@@ -33,6 +33,8 @@ export default Controller.extend({
showQuickFilterUnconfirmed: false, showQuickFilterUnconfirmed: false,
showQuickFilterConfirmed: false, showQuickFilterConfirmed: false,
showFullContributionSync: gt('kredits.missingHistoricContributionsCount', 0),
showIntroText: computed('kredits.{hasAccounts,currentUser}', function(){ showIntroText: computed('kredits.{hasAccounts,currentUser}', function(){
return (!this.kredits.hasAccounts || !this.kredits.currentUser); return (!this.kredits.hasAccounts || !this.kredits.currentUser);
}), }),
+5 -2
View File
@@ -11,8 +11,11 @@ export default class DashboardRoute extends Route {
schedule('afterRender', this.kredits.syncContributions, schedule('afterRender', this.kredits.syncContributions,
this.kredits.syncContributions.perform); this.kredits.syncContributions.perform);
} }
schedule('afterRender', this.kredits.fetchMissingContributions, // TODO fetch automatically under a certain threshold
this.kredits.fetchMissingContributions.perform); // The browser might delete cached data and we don't need manual re-syncs
// depending on how little is missing
// schedule('afterRender', this.kredits.fetchMissingContributions,
// this.kredits.fetchMissingContributions.perform);
} }
} }
+14 -3
View File
@@ -48,6 +48,8 @@ export default Service.extend({
contributionsNeedSync: false, contributionsNeedSync: false,
reimbursementsNeedSync: false, reimbursementsNeedSync: false,
missingHistoricContributionsCount: 0,
init () { init () {
this._super(...arguments); this._super(...arguments);
this.set('contributors', []); this.set('contributors', []);
@@ -230,12 +232,20 @@ export default Service.extend({
await this.loadObjectsFromCache('Contribution'); await this.loadObjectsFromCache('Contribution');
this.set('contributionsNeedSync', true); this.set('contributionsNeedSync', true);
} else { } else {
await this.fetchContributions({ page: { size: 30 } }); await this.fetchContributions({ page: { size: 40 } });
} }
await this.updateMissingHistoricContributionsCount();
return Promise.resolve(); 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) { addContributor (attributes) {
if (attributes.github_uid) { if (attributes.github_uid) {
const uidInt = parseInt(attributes.github_uid); const uidInt = parseInt(attributes.github_uid);
@@ -371,11 +381,12 @@ export default Service.extend({
syncContributions: task(function * () { syncContributions: task(function * () {
yield this.fetchNewContributions.perform(); yield this.fetchNewContributions.perform();
yield this.syncUnconfirmedContributions.perform(); yield this.syncUnconfirmedContributions.perform();
yield this.updateMissingHistoricContributionsCount();
this.set('contributionsNeedSync', false); this.set('contributionsNeedSync', false);
}).group('contributionTasks'), }).group('contributionTasks'),
fetchNewContributions: task(function * () { 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 lastKnownContributionId = Math.max.apply(null, this.contributions.mapBy('id'));
const toFetch = count - lastKnownContributionId; const toFetch = count - lastKnownContributionId;
@@ -392,7 +403,7 @@ export default Service.extend({
}), }),
fetchMissingContributions: task(function * () { fetchMissingContributions: task(function * () {
const count = yield this.kredits.Contribution.functions.contributionsCount(); const count = yield this.kredits.Contribution.count;
const allIds = [...Array(count+1).keys()]; const allIds = [...Array(count+1).keys()];
allIds.shift(); // remove first item, which is 0 allIds.shift(); // remove first item, which is 0
const loadedContributions = new Set(this.contributions.mapBy('id')); const loadedContributions = new Set(this.contributions.mapBy('id'));
+26
View File
@@ -105,6 +105,32 @@
@showQuickFilter={{this.showQuickFilterConfirmed}} /> @showQuickFilter={{this.showQuickFilterConfirmed}} />
</div> </div>
</section> </section>
{{#if this.showFullContributionSync}}
<section id="sync-all-contributions">
{{#if this.kredits.fetchMissingContributions.isIdle}}
<p style="margin-bottom: 1rem;">
There are
<strong>{{this.kredits.missingHistoricContributionsCount}}</strong>
contributions, which are not currently loaded/displayed.
</p>
<p>
You can fetch all historic data in one go, and have it stored locally in
your browser:
<button type="button" {{on "click" (perform this.kredits.fetchMissingContributions)}} class="small">
fetch all data
</button>
</p>
{{else}}
<p style="margin-bottom: 1rem;">
Syncing data. Please be patient...
</p>
<p>
(You can leave this website anytime and sync missing data when you come back.)
</p>
{{/if}}
</section>
{{/if}}
</div> </div>
<div id="details"> <div id="details">