MOBILE-3001 course: Don't prefetch ratings and profiles

main
Dani Palou 2019-05-15 13:56:52 +02:00
parent a8037b80b7
commit 75b4982224
4 changed files with 26 additions and 69 deletions

View File

@ -24,7 +24,6 @@ import { CoreTimeUtilsProvider } from '@providers/utils/time';
import { CoreCommentsProvider } from '@core/comments/providers/comments'; import { CoreCommentsProvider } from '@core/comments/providers/comments';
import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseActivityPrefetchHandlerBase } from '@core/course/classes/activity-prefetch-handler'; import { CoreCourseActivityPrefetchHandlerBase } from '@core/course/classes/activity-prefetch-handler';
import { CoreRatingProvider } from '@core/rating/providers/rating';
import { AddonModDataProvider, AddonModDataEntry } from './data'; import { AddonModDataProvider, AddonModDataEntry } from './data';
import { AddonModDataSyncProvider } from './sync'; import { AddonModDataSyncProvider } from './sync';
import { AddonModDataHelperProvider } from './helper'; import { AddonModDataHelperProvider } from './helper';
@ -44,7 +43,7 @@ export class AddonModDataPrefetchHandler extends CoreCourseActivityPrefetchHandl
domUtils: CoreDomUtilsProvider, protected dataProvider: AddonModDataProvider, domUtils: CoreDomUtilsProvider, protected dataProvider: AddonModDataProvider,
protected timeUtils: CoreTimeUtilsProvider, protected dataHelper: AddonModDataHelperProvider, protected timeUtils: CoreTimeUtilsProvider, protected dataHelper: AddonModDataHelperProvider,
protected groupsProvider: CoreGroupsProvider, protected commentsProvider: CoreCommentsProvider, protected groupsProvider: CoreGroupsProvider, protected commentsProvider: CoreCommentsProvider,
private ratingProvider: CoreRatingProvider, protected syncProvider: AddonModDataSyncProvider) { protected syncProvider: AddonModDataSyncProvider) {
super(translate, appProvider, utils, courseProvider, filepoolProvider, sitesProvider, domUtils); super(translate, appProvider, utils, courseProvider, filepoolProvider, sitesProvider, domUtils);
} }
@ -285,10 +284,7 @@ export class AddonModDataPrefetchHandler extends CoreCourseActivityPrefetchHandl
}); });
info.entries.forEach((entry) => { info.entries.forEach((entry) => {
promises.push(this.dataProvider.getEntry(database.id, entry.id, true, siteId).then((entry) => { promises.push(this.dataProvider.getEntry(database.id, entry.id, true, siteId));
return this.ratingProvider.prefetchRatings('module', module.id, database.scale, courseId, entry.ratinginfo,
siteId);
}));
if (database.comments) { if (database.comments) {
promises.push(this.commentsProvider.getComments('module', database.coursemodule, 'mod_data', entry.id, promises.push(this.commentsProvider.getComments('module', database.coursemodule, 'mod_data', entry.id,

View File

@ -26,7 +26,6 @@ import { AddonModFeedbackHelperProvider } from './helper';
import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreTimeUtilsProvider } from '@providers/utils/time';
import { CoreGroupsProvider } from '@providers/groups'; import { CoreGroupsProvider } from '@providers/groups';
import { AddonModFeedbackSyncProvider } from './sync'; import { AddonModFeedbackSyncProvider } from './sync';
import { CoreUserProvider } from '@core/user/providers/user';
/** /**
* Handler to prefetch feedbacks. * Handler to prefetch feedbacks.
@ -43,7 +42,7 @@ export class AddonModFeedbackPrefetchHandler extends CoreCourseActivityPrefetchH
constructor(translate: TranslateService, appProvider: CoreAppProvider, utils: CoreUtilsProvider, constructor(translate: TranslateService, appProvider: CoreAppProvider, utils: CoreUtilsProvider,
courseProvider: CoreCourseProvider, filepoolProvider: CoreFilepoolProvider, sitesProvider: CoreSitesProvider, courseProvider: CoreCourseProvider, filepoolProvider: CoreFilepoolProvider, sitesProvider: CoreSitesProvider,
domUtils: CoreDomUtilsProvider, protected feedbackProvider: AddonModFeedbackProvider, domUtils: CoreDomUtilsProvider, protected feedbackProvider: AddonModFeedbackProvider,
protected userProvider: CoreUserProvider, protected feedbackHelper: AddonModFeedbackHelperProvider, protected feedbackHelper: AddonModFeedbackHelperProvider,
protected timeUtils: CoreTimeUtilsProvider, protected groupsProvider: CoreGroupsProvider, protected timeUtils: CoreTimeUtilsProvider, protected groupsProvider: CoreGroupsProvider,
protected injector: Injector) { protected injector: Injector) {
@ -187,35 +186,21 @@ export class AddonModFeedbackPrefetchHandler extends CoreCourseActivityPrefetchH
p2.push(this.feedbackProvider.getAnalysis(feedback.id, undefined, true, siteId)); p2.push(this.feedbackProvider.getAnalysis(feedback.id, undefined, true, siteId));
p2.push(this.groupsProvider.getActivityGroupInfo(feedback.coursemodule, true, undefined, siteId, true) p2.push(this.groupsProvider.getActivityGroupInfo(feedback.coursemodule, true, undefined, siteId, true)
.then((groupInfo) => { .then((groupInfo) => {
const p3 = [], const p3 = [];
userIds = [];
if (!groupInfo.groups || groupInfo.groups.length == 0) { if (!groupInfo.groups || groupInfo.groups.length == 0) {
groupInfo.groups = [{id: 0}]; groupInfo.groups = [{id: 0}];
} }
groupInfo.groups.forEach((group) => { groupInfo.groups.forEach((group) => {
p3.push(this.feedbackProvider.getAnalysis(feedback.id, group.id, true, siteId)); p3.push(this.feedbackProvider.getAnalysis(feedback.id, group.id, true, siteId));
p3.push(this.feedbackProvider.getAllResponsesAnalysis(feedback.id, group.id, true, siteId) p3.push(this.feedbackProvider.getAllResponsesAnalysis(feedback.id, group.id, true, siteId));
.then((responses) => {
responses.attempts.forEach((attempt) => {
userIds.push(attempt.userid);
});
}));
if (!accessData.isanonymous) { if (!accessData.isanonymous) {
p3.push(this.feedbackProvider.getAllNonRespondents(feedback.id, group.id, true, siteId) p3.push(this.feedbackProvider.getAllNonRespondents(feedback.id, group.id, true, siteId));
.then((responses) => {
responses.users.forEach((user) => {
userIds.push(user.userid);
});
}));
} }
}); });
return Promise.all(p3).then(() => { return Promise.all(p3);
// Prefetch user profiles.
return this.userProvider.prefetchProfiles(userIds, courseId, siteId);
});
})); }));
} }

View File

@ -22,10 +22,8 @@ import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseActivityPrefetchHandlerBase } from '@core/course/classes/activity-prefetch-handler'; import { CoreCourseActivityPrefetchHandlerBase } from '@core/course/classes/activity-prefetch-handler';
import { CoreGroupsProvider } from '@providers/groups'; import { CoreGroupsProvider } from '@providers/groups';
import { CoreUserProvider } from '@core/user/providers/user';
import { AddonModForumProvider } from './forum'; import { AddonModForumProvider } from './forum';
import { AddonModForumSyncProvider } from './sync'; import { AddonModForumSyncProvider } from './sync';
import { CoreRatingProvider, CoreRatingInfo } from '@core/rating/providers/rating';
/** /**
* Handler to prefetch forums. * Handler to prefetch forums.
@ -45,9 +43,7 @@ export class AddonModForumPrefetchHandler extends CoreCourseActivityPrefetchHand
sitesProvider: CoreSitesProvider, sitesProvider: CoreSitesProvider,
domUtils: CoreDomUtilsProvider, domUtils: CoreDomUtilsProvider,
private groupsProvider: CoreGroupsProvider, private groupsProvider: CoreGroupsProvider,
private userProvider: CoreUserProvider,
private forumProvider: AddonModForumProvider, private forumProvider: AddonModForumProvider,
private ratingProvider: CoreRatingProvider,
private syncProvider: AddonModForumSyncProvider) { private syncProvider: AddonModForumSyncProvider) {
super(translate, appProvider, utils, courseProvider, filepoolProvider, sitesProvider, domUtils); super(translate, appProvider, utils, courseProvider, filepoolProvider, sitesProvider, domUtils);
@ -107,9 +103,6 @@ export class AddonModForumPrefetchHandler extends CoreCourseActivityPrefetchHand
* @return {Promise<any[]>} Promise resolved with array of posts. * @return {Promise<any[]>} Promise resolved with array of posts.
*/ */
protected getPostsForPrefetch(forum: any): Promise<any[]> { protected getPostsForPrefetch(forum: any): Promise<any[]> {
const posts = {};
const ratingInfos: CoreRatingInfo[] = [];
const promises = this.forumProvider.getAvailableSortOrders().map((sortOrder) => { const promises = this.forumProvider.getAvailableSortOrders().map((sortOrder) => {
// Get discussions in first 2 pages. // Get discussions in first 2 pages.
return this.forumProvider.getDiscussionsInPages(forum.id, sortOrder.value, false, 2).then((response) => { return this.forumProvider.getDiscussionsInPages(forum.id, sortOrder.value, false, 2).then((response) => {
@ -120,25 +113,14 @@ export class AddonModForumPrefetchHandler extends CoreCourseActivityPrefetchHand
const promises = []; const promises = [];
response.discussions.forEach((discussion) => { response.discussions.forEach((discussion) => {
promises.push(this.forumProvider.getDiscussionPosts(discussion.discussion).then((response) => { promises.push(this.forumProvider.getDiscussionPosts(discussion.discussion));
response.posts.forEach((post) => {
posts[post.id] = post;
});
ratingInfos.push(response.ratinginfo);
}));
}); });
return Promise.all(promises); return Promise.all(promises);
}); });
}); });
return Promise.all(promises).then(() => { return Promise.all(promises);
const ratingInfo = this.ratingProvider.mergeRatingInfos(ratingInfos);
return this.ratingProvider.prefetchRatings('module', forum.cmid, forum.scale, forum.course, ratingInfo).then(() => {
return this.utils.objectToArray(posts);
});
});
} }
/** /**
@ -201,14 +183,18 @@ export class AddonModForumPrefetchHandler extends CoreCourseActivityPrefetchHand
promises.push(this.getPostsForPrefetch(forum).then((posts) => { promises.push(this.getPostsForPrefetch(forum).then((posts) => {
const promises = []; const promises = [];
// Prefetch user profiles. // Gather user profile images.
const userIds = posts.map((post) => post.userid).filter((userId) => !!userId); const avatars = {}; // List of user avatars, preventing duplicates.
promises.push(this.userProvider.prefetchProfiles(userIds).catch(() => {
// Ignore failures.
}));
// Prefetch intro files, attachments and embedded files. posts.forEach((post) => {
const files = this.getIntroFilesFromInstance(module, forum).concat(this.getPostsFiles(posts)); if (post.userpictureurl) {
avatars[post.userpictureurl] = true;
}
});
// Prefetch intro files, attachments, embedded files and user avatars.
const files = this.getIntroFilesFromInstance(module, forum).concat(this.getPostsFiles(posts))
.concat(Object.keys(avatars));
promises.push(this.filepoolProvider.addFilesToQueue(siteId, files, this.component, module.id)); promises.push(this.filepoolProvider.addFilesToQueue(siteId, files, this.component, module.id));
// Prefetch groups data. // Prefetch groups data.

View File

@ -21,9 +21,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseActivityPrefetchHandlerBase } from '@core/course/classes/activity-prefetch-handler'; import { CoreCourseActivityPrefetchHandlerBase } from '@core/course/classes/activity-prefetch-handler';
import { CoreUserProvider } from '@core/user/providers/user';
import { AddonModGlossaryProvider } from './glossary'; import { AddonModGlossaryProvider } from './glossary';
import { CoreRatingProvider } from '@core/rating/providers/rating';
import { AddonModGlossarySyncProvider } from './sync'; import { AddonModGlossarySyncProvider } from './sync';
/** /**
@ -43,8 +41,6 @@ export class AddonModGlossaryPrefetchHandler extends CoreCourseActivityPrefetchH
filepoolProvider: CoreFilepoolProvider, filepoolProvider: CoreFilepoolProvider,
sitesProvider: CoreSitesProvider, sitesProvider: CoreSitesProvider,
domUtils: CoreDomUtilsProvider, domUtils: CoreDomUtilsProvider,
private userProvider: CoreUserProvider,
private ratingProvider: CoreRatingProvider,
private glossaryProvider: AddonModGlossaryProvider, private glossaryProvider: AddonModGlossaryProvider,
private syncProvider: AddonModGlossarySyncProvider) { private syncProvider: AddonModGlossarySyncProvider) {
@ -163,24 +159,18 @@ export class AddonModGlossaryPrefetchHandler extends CoreCourseActivityPrefetchH
promises.push(this.glossaryProvider.fetchAllEntries(this.glossaryProvider.getEntriesByLetter, promises.push(this.glossaryProvider.fetchAllEntries(this.glossaryProvider.getEntriesByLetter,
[glossary.id, 'ALL'], false, siteId).then((entries) => { [glossary.id, 'ALL'], false, siteId).then((entries) => {
const promises = []; const promises = [];
const userIds = []; const avatars = {}; // List of user avatars, preventing duplicates.
// Fetch user avatars.
entries.forEach((entry) => { entries.forEach((entry) => {
// Fetch individual entries. // Fetch individual entries.
promises.push(this.glossaryProvider.getEntry(entry.id, siteId).then((entry) => { promises.push(this.glossaryProvider.getEntry(entry.id, siteId));
// Fetch individual ratings.
return this.ratingProvider.prefetchRatings('module', module.id, glossary.scale, courseId, entry.ratinginfo,
siteId);
}));
userIds.push(entry.userid); if (entry.userpictureurl) {
avatars[entry.userpictureurl] = true;
}
}); });
// Prefetch user profiles. const files = this.getFilesFromGlossaryAndEntries(module, glossary, entries).concat(Object.keys(avatars));
promises.push(this.userProvider.prefetchProfiles(userIds, courseId, siteId));
const files = this.getFilesFromGlossaryAndEntries(module, glossary, entries);
promises.push(this.filepoolProvider.addFilesToQueue(siteId, files, this.component, module.id)); promises.push(this.filepoolProvider.addFilesToQueue(siteId, files, this.component, module.id));
return Promise.all(promises); return Promise.all(promises);