MOBILE-3001 course: Don't prefetch ratings and profiles
parent
a8037b80b7
commit
75b4982224
|
@ -24,7 +24,6 @@ import { CoreTimeUtilsProvider } from '@providers/utils/time';
|
|||
import { CoreCommentsProvider } from '@core/comments/providers/comments';
|
||||
import { CoreCourseProvider } from '@core/course/providers/course';
|
||||
import { CoreCourseActivityPrefetchHandlerBase } from '@core/course/classes/activity-prefetch-handler';
|
||||
import { CoreRatingProvider } from '@core/rating/providers/rating';
|
||||
import { AddonModDataProvider, AddonModDataEntry } from './data';
|
||||
import { AddonModDataSyncProvider } from './sync';
|
||||
import { AddonModDataHelperProvider } from './helper';
|
||||
|
@ -44,7 +43,7 @@ export class AddonModDataPrefetchHandler extends CoreCourseActivityPrefetchHandl
|
|||
domUtils: CoreDomUtilsProvider, protected dataProvider: AddonModDataProvider,
|
||||
protected timeUtils: CoreTimeUtilsProvider, protected dataHelper: AddonModDataHelperProvider,
|
||||
protected groupsProvider: CoreGroupsProvider, protected commentsProvider: CoreCommentsProvider,
|
||||
private ratingProvider: CoreRatingProvider, protected syncProvider: AddonModDataSyncProvider) {
|
||||
protected syncProvider: AddonModDataSyncProvider) {
|
||||
|
||||
super(translate, appProvider, utils, courseProvider, filepoolProvider, sitesProvider, domUtils);
|
||||
}
|
||||
|
@ -285,10 +284,7 @@ export class AddonModDataPrefetchHandler extends CoreCourseActivityPrefetchHandl
|
|||
});
|
||||
|
||||
info.entries.forEach((entry) => {
|
||||
promises.push(this.dataProvider.getEntry(database.id, entry.id, true, siteId).then((entry) => {
|
||||
return this.ratingProvider.prefetchRatings('module', module.id, database.scale, courseId, entry.ratinginfo,
|
||||
siteId);
|
||||
}));
|
||||
promises.push(this.dataProvider.getEntry(database.id, entry.id, true, siteId));
|
||||
|
||||
if (database.comments) {
|
||||
promises.push(this.commentsProvider.getComments('module', database.coursemodule, 'mod_data', entry.id,
|
||||
|
|
|
@ -26,7 +26,6 @@ import { AddonModFeedbackHelperProvider } from './helper';
|
|||
import { CoreTimeUtilsProvider } from '@providers/utils/time';
|
||||
import { CoreGroupsProvider } from '@providers/groups';
|
||||
import { AddonModFeedbackSyncProvider } from './sync';
|
||||
import { CoreUserProvider } from '@core/user/providers/user';
|
||||
|
||||
/**
|
||||
* Handler to prefetch feedbacks.
|
||||
|
@ -43,7 +42,7 @@ export class AddonModFeedbackPrefetchHandler extends CoreCourseActivityPrefetchH
|
|||
constructor(translate: TranslateService, appProvider: CoreAppProvider, utils: CoreUtilsProvider,
|
||||
courseProvider: CoreCourseProvider, filepoolProvider: CoreFilepoolProvider, sitesProvider: CoreSitesProvider,
|
||||
domUtils: CoreDomUtilsProvider, protected feedbackProvider: AddonModFeedbackProvider,
|
||||
protected userProvider: CoreUserProvider, protected feedbackHelper: AddonModFeedbackHelperProvider,
|
||||
protected feedbackHelper: AddonModFeedbackHelperProvider,
|
||||
protected timeUtils: CoreTimeUtilsProvider, protected groupsProvider: CoreGroupsProvider,
|
||||
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.groupsProvider.getActivityGroupInfo(feedback.coursemodule, true, undefined, siteId, true)
|
||||
.then((groupInfo) => {
|
||||
const p3 = [],
|
||||
userIds = [];
|
||||
const p3 = [];
|
||||
|
||||
if (!groupInfo.groups || groupInfo.groups.length == 0) {
|
||||
groupInfo.groups = [{id: 0}];
|
||||
}
|
||||
groupInfo.groups.forEach((group) => {
|
||||
p3.push(this.feedbackProvider.getAnalysis(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);
|
||||
});
|
||||
}));
|
||||
p3.push(this.feedbackProvider.getAllResponsesAnalysis(feedback.id, group.id, true, siteId));
|
||||
|
||||
if (!accessData.isanonymous) {
|
||||
p3.push(this.feedbackProvider.getAllNonRespondents(feedback.id, group.id, true, siteId)
|
||||
.then((responses) => {
|
||||
responses.users.forEach((user) => {
|
||||
userIds.push(user.userid);
|
||||
});
|
||||
}));
|
||||
p3.push(this.feedbackProvider.getAllNonRespondents(feedback.id, group.id, true, siteId));
|
||||
}
|
||||
});
|
||||
|
||||
return Promise.all(p3).then(() => {
|
||||
// Prefetch user profiles.
|
||||
return this.userProvider.prefetchProfiles(userIds, courseId, siteId);
|
||||
});
|
||||
return Promise.all(p3);
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,8 @@ import { CoreUtilsProvider } from '@providers/utils/utils';
|
|||
import { CoreCourseProvider } from '@core/course/providers/course';
|
||||
import { CoreCourseActivityPrefetchHandlerBase } from '@core/course/classes/activity-prefetch-handler';
|
||||
import { CoreGroupsProvider } from '@providers/groups';
|
||||
import { CoreUserProvider } from '@core/user/providers/user';
|
||||
import { AddonModForumProvider } from './forum';
|
||||
import { AddonModForumSyncProvider } from './sync';
|
||||
import { CoreRatingProvider, CoreRatingInfo } from '@core/rating/providers/rating';
|
||||
|
||||
/**
|
||||
* Handler to prefetch forums.
|
||||
|
@ -45,9 +43,7 @@ export class AddonModForumPrefetchHandler extends CoreCourseActivityPrefetchHand
|
|||
sitesProvider: CoreSitesProvider,
|
||||
domUtils: CoreDomUtilsProvider,
|
||||
private groupsProvider: CoreGroupsProvider,
|
||||
private userProvider: CoreUserProvider,
|
||||
private forumProvider: AddonModForumProvider,
|
||||
private ratingProvider: CoreRatingProvider,
|
||||
private syncProvider: AddonModForumSyncProvider) {
|
||||
|
||||
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.
|
||||
*/
|
||||
protected getPostsForPrefetch(forum: any): Promise<any[]> {
|
||||
const posts = {};
|
||||
const ratingInfos: CoreRatingInfo[] = [];
|
||||
|
||||
const promises = this.forumProvider.getAvailableSortOrders().map((sortOrder) => {
|
||||
// Get discussions in first 2 pages.
|
||||
return this.forumProvider.getDiscussionsInPages(forum.id, sortOrder.value, false, 2).then((response) => {
|
||||
|
@ -120,25 +113,14 @@ export class AddonModForumPrefetchHandler extends CoreCourseActivityPrefetchHand
|
|||
const promises = [];
|
||||
|
||||
response.discussions.forEach((discussion) => {
|
||||
promises.push(this.forumProvider.getDiscussionPosts(discussion.discussion).then((response) => {
|
||||
response.posts.forEach((post) => {
|
||||
posts[post.id] = post;
|
||||
});
|
||||
ratingInfos.push(response.ratinginfo);
|
||||
}));
|
||||
promises.push(this.forumProvider.getDiscussionPosts(discussion.discussion));
|
||||
});
|
||||
|
||||
return Promise.all(promises);
|
||||
});
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(() => {
|
||||
const ratingInfo = this.ratingProvider.mergeRatingInfos(ratingInfos);
|
||||
|
||||
return this.ratingProvider.prefetchRatings('module', forum.cmid, forum.scale, forum.course, ratingInfo).then(() => {
|
||||
return this.utils.objectToArray(posts);
|
||||
});
|
||||
});
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -201,14 +183,18 @@ export class AddonModForumPrefetchHandler extends CoreCourseActivityPrefetchHand
|
|||
promises.push(this.getPostsForPrefetch(forum).then((posts) => {
|
||||
const promises = [];
|
||||
|
||||
// Prefetch user profiles.
|
||||
const userIds = posts.map((post) => post.userid).filter((userId) => !!userId);
|
||||
promises.push(this.userProvider.prefetchProfiles(userIds).catch(() => {
|
||||
// Ignore failures.
|
||||
}));
|
||||
// Gather user profile images.
|
||||
const avatars = {}; // List of user avatars, preventing duplicates.
|
||||
|
||||
// Prefetch intro files, attachments and embedded files.
|
||||
const files = this.getIntroFilesFromInstance(module, forum).concat(this.getPostsFiles(posts));
|
||||
posts.forEach((post) => {
|
||||
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));
|
||||
|
||||
// Prefetch groups data.
|
||||
|
|
|
@ -21,9 +21,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
|||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CoreCourseProvider } from '@core/course/providers/course';
|
||||
import { CoreCourseActivityPrefetchHandlerBase } from '@core/course/classes/activity-prefetch-handler';
|
||||
import { CoreUserProvider } from '@core/user/providers/user';
|
||||
import { AddonModGlossaryProvider } from './glossary';
|
||||
import { CoreRatingProvider } from '@core/rating/providers/rating';
|
||||
import { AddonModGlossarySyncProvider } from './sync';
|
||||
|
||||
/**
|
||||
|
@ -43,8 +41,6 @@ export class AddonModGlossaryPrefetchHandler extends CoreCourseActivityPrefetchH
|
|||
filepoolProvider: CoreFilepoolProvider,
|
||||
sitesProvider: CoreSitesProvider,
|
||||
domUtils: CoreDomUtilsProvider,
|
||||
private userProvider: CoreUserProvider,
|
||||
private ratingProvider: CoreRatingProvider,
|
||||
private glossaryProvider: AddonModGlossaryProvider,
|
||||
private syncProvider: AddonModGlossarySyncProvider) {
|
||||
|
||||
|
@ -163,24 +159,18 @@ export class AddonModGlossaryPrefetchHandler extends CoreCourseActivityPrefetchH
|
|||
promises.push(this.glossaryProvider.fetchAllEntries(this.glossaryProvider.getEntriesByLetter,
|
||||
[glossary.id, 'ALL'], false, siteId).then((entries) => {
|
||||
const promises = [];
|
||||
const userIds = [];
|
||||
const avatars = {}; // List of user avatars, preventing duplicates.
|
||||
|
||||
// Fetch user avatars.
|
||||
entries.forEach((entry) => {
|
||||
// Fetch individual entries.
|
||||
promises.push(this.glossaryProvider.getEntry(entry.id, siteId).then((entry) => {
|
||||
// Fetch individual ratings.
|
||||
return this.ratingProvider.prefetchRatings('module', module.id, glossary.scale, courseId, entry.ratinginfo,
|
||||
siteId);
|
||||
}));
|
||||
promises.push(this.glossaryProvider.getEntry(entry.id, siteId));
|
||||
|
||||
userIds.push(entry.userid);
|
||||
if (entry.userpictureurl) {
|
||||
avatars[entry.userpictureurl] = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Prefetch user profiles.
|
||||
promises.push(this.userProvider.prefetchProfiles(userIds, courseId, siteId));
|
||||
|
||||
const files = this.getFilesFromGlossaryAndEntries(module, glossary, entries);
|
||||
const files = this.getFilesFromGlossaryAndEntries(module, glossary, entries).concat(Object.keys(avatars));
|
||||
promises.push(this.filepoolProvider.addFilesToQueue(siteId, files, this.component, module.id));
|
||||
|
||||
return Promise.all(promises);
|
||||
|
|
Loading…
Reference in New Issue