Skip to content

Further speed improvements with LFD initial load #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions js/layout-javascript/agenda-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function DynamicList(id, data) {
this.agendaDates = [];
this.showBookmarks;
this.fetchedAllBookmarks = false;
this.allFilterPropertiesAdded = false;
this.searchValue = '';
this.activeFilters = {};

Expand Down Expand Up @@ -1029,7 +1030,7 @@ DynamicList.prototype.initialize = function() {
});
})
.then(function(records) {
_this.listItems = _this.getPermissions(records);
_this.listItems = records;

return _this.Utils.Records.getFields(_this.listItems, _this.data.dataSourceId).then(function(columns) {
_this.dataSourceColumns = columns;
Expand All @@ -1048,12 +1049,13 @@ DynamicList.prototype.initialize = function() {
.then(function(response) {
_this.listItems = _.uniqBy(response, 'id');
_this.checkIsToOpen();
_this.modifiedListItems = _this.Utils.Records.addFilterProperties({
_this.listItems = _this.Utils.Records.addFilterProperties({
records: _this.listItems,
config: _this.data
});
_this.allFilterPropertiesAdded = true;

return _this.addFilters(_this.modifiedListItems);
return _this.addFilters(_this.listItems);
}).then(function() {
_this.parseFilterQueries();
_this.parseSearchQueries();
Expand Down Expand Up @@ -1307,19 +1309,21 @@ DynamicList.prototype.groupLoopDataByDate = function(loopData, dateField) {

DynamicList.prototype.addSummaryData = function(records) {
var _this = this;
var modifiedData = _this.Utils.Records.addFilterProperties({
records: records,
config: _this.data
});
var modifiedData = records;

if (!_this.allFilterPropertiesAdded) {
modifiedData = _this.Utils.Records.addFilterProperties({
records: modifiedData,
config: _this.data
});
}

// Uses sumamry view settings set by users
var loopData = _.map(modifiedData, function(entry) {
var newObject = {
id: entry.id,
flClasses: entry.data['flClasses'],
flFilters: entry.data['flFilters'],
editEntry: entry.editEntry,
deleteEntry: entry.deleteEntry,
pollButton: _this.data.pollEnabled
&& entry.data[_this.data.pollColumn]
&& entry.data[_this.data.pollColumn] !== '',
Expand Down Expand Up @@ -1551,16 +1555,16 @@ DynamicList.prototype.getAddPermission = function(data) {
return data;
};

DynamicList.prototype.getPermissions = function(entries) {
var _this = this;
DynamicList.prototype.addPermissions = function(entry) {
if (!_.isObject(entry)) {
return entry;
}

// Adds flag for Edit and Delete buttons
_.forEach(entries, function(entry) {
entry.editEntry = _this.Utils.Record.isEditable(entry, _this.data, _this.myUserData);
entry.deleteEntry = _this.Utils.Record.isDeletable(entry, _this.data, _this.myUserData);
});
entry.editEntry = this.Utils.Record.isEditable(entry, this.data, this.myUserData);
entry.deleteEntry = this.Utils.Record.isDeletable(entry, this.data, this.myUserData);

return entries;
return entry;
};

DynamicList.prototype.addFilters = function(records) {
Expand Down Expand Up @@ -1677,7 +1681,7 @@ DynamicList.prototype.getAllBookmarks = function() {
})
}).then(function(results) {
var bookmarkedIds = _.compact(_.map(results.data, function(record) {
var match = _.get(record, 'data.content.entryId', '').match(/(\d*)-bookmark/);
var match = ((record.data && record.data.content && record.data.content.entryId) || '').match(/(\d*)-bookmark/);

return match ? parseInt(match[1], 10) : '';
}));
Expand Down Expand Up @@ -2519,6 +2523,7 @@ DynamicList.prototype.addDetailViewData = function(entry) {
return option.editable;
});

entry = _this.addPermissions(entry);
entry.entryDetails = [];

// Uses detail view settings not set by users
Expand Down
74 changes: 40 additions & 34 deletions js/layout-javascript/news-feed-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function DynamicList(id, data) {
this.isSearching;
this.showBookmarks;
this.fetchedAllBookmarks = false;
this.allFilterPropertiesAdded = false;
this.searchValue = '';
this.activeFilters = {};

Expand Down Expand Up @@ -1126,7 +1127,7 @@ DynamicList.prototype.initializeOverlaySocials = function(id) {
DynamicList.prototype.getAllBookmarks = function() {
var _this = this;

if (_this.fetchedAllBookmarks || !_.get(_this.data, 'social.bookmark') || !_this.data.bookmarkDataSourceId) {
if (_this.fetchedAllBookmarks || !(_this.data.social && _this.data.social.bookmark) || !_this.data.bookmarkDataSourceId) {
return Promise.resolve();
}

Expand All @@ -1152,7 +1153,7 @@ DynamicList.prototype.getAllBookmarks = function() {
})
}).then(function(results) {
var bookmarkedIds = _.compact(_.map(results.data, function(record) {
var match = _.get(record, 'data.content.entryId', '').match(/(\d*)-bookmark/);
var match = ((record.data && record.data.content && record.data.content.entryId) || '').match(/(\d*)-bookmark/);

return match ? parseInt(match[1], 10) : '';
}));
Expand Down Expand Up @@ -1206,7 +1207,7 @@ DynamicList.prototype.initializeSocials = function(records) {
};

DynamicList.prototype.getCommentUsers = function() {
if (!_.get(this.data, 'social.comments')) {
if (!(this.data.social && this.data.social.comments)) {
return Promise.resolve();
}

Expand All @@ -1229,14 +1230,14 @@ DynamicList.prototype.getCommentUsers = function() {
_this.allUsers = users;

// Update my user data
if (!_.isEmpty(_this.myUserData)) {
var myUser = _.find(_this.allUsers, function(user) {
return _this.myUserData[_this.data.userEmailColumn] === user.data[_this.data.userEmailColumn];
});
if (_this.myUserData) {
_this.allUsers.some(function(user) {
if (_this.myUserData[_this.data.userEmailColumn] === user.data[_this.data.userEmailColumn]) {
_this.myUserData = $.extend(true, _this.myUserData, user.data);

if (myUser) {
_this.myUserData = $.extend(true, _this.myUserData, myUser.data);
}
return true;
}
});
}

return _this.Utils.Users.getUsersToMention({
Expand Down Expand Up @@ -1299,7 +1300,7 @@ DynamicList.prototype.initialize = function() {
});
})
.then(function(records) {
_this.listItems = _this.getPermissions(records);
_this.listItems = records;

if (!_this.data.detailViewAutoUpdate) {
return Promise.resolve();
Expand All @@ -1318,12 +1319,13 @@ DynamicList.prototype.initialize = function() {
.then(function(response) {
_this.listItems = _.uniqBy(response, 'id');
_this.checkIsToOpen();
_this.modifiedListItems = _this.Utils.Records.addFilterProperties({
_this.listItems = _this.Utils.Records.addFilterProperties({
records: _this.listItems,
config: _this.data
});
_this.allFilterPropertiesAdded = true;

return _this.addFilters(_this.modifiedListItems);
return _this.addFilters(_this.listItems);
})
.then(function() {
_this.parseFilterQueries();
Expand Down Expand Up @@ -1369,7 +1371,7 @@ DynamicList.prototype.parseSearchQueries = function() {
var _this = this;

if (!_.get(_this.pvSearchQuery, 'value')) {
// Continue to exectute query filters
// Continue to execute query filters
return _this.searchData({
initialRender: true
});
Expand Down Expand Up @@ -1604,17 +1606,20 @@ DynamicList.prototype.renderBaseHTML = function() {

DynamicList.prototype.addSummaryData = function(records) {
var _this = this;
var modifiedData = _this.Utils.Records.addFilterProperties({
records: records,
config: _this.data
});
var modifiedData = records;

if (!_this.allFilterPropertiesAdded) {
modifiedData = _this.Utils.Records.addFilterProperties({
records: modifiedData,
config: _this.data
});
}

var loopData = _.map(modifiedData, function(entry) {
var newObject = {
id: entry.id,
flClasses: entry.data['flClasses'],
flFilters: entry.data['flFilters'],
editEntry: entry.editEntry,
deleteEntry: entry.deleteEntry,
likesEnabled: entry.likesEnabled,
bookmarksEnabled: entry.bookmarksEnabled,
commentsEnabled: entry.commentsEnabled,
Expand Down Expand Up @@ -1707,16 +1712,16 @@ DynamicList.prototype.getAddPermission = function(data) {
return data;
};

DynamicList.prototype.getPermissions = function(entries) {
var _this = this;
DynamicList.prototype.addPermissions = function(entry) {
if (!_.isObject(entry)) {
return entry;
}

// Adds flag for Edit and Delete buttons
_.forEach(entries, function(entry) {
entry.editEntry = _this.Utils.Record.isEditable(entry, _this.data, _this.myUserData);
entry.deleteEntry = _this.Utils.Record.isDeletable(entry, _this.data, _this.myUserData);
});
entry.editEntry = this.Utils.Record.isEditable(entry, this.data, this.myUserData);
entry.deleteEntry = this.Utils.Record.isDeletable(entry, this.data, this.myUserData);

return entries;
return entry;
};

DynamicList.prototype.addFilters = function(records) {
Expand Down Expand Up @@ -2012,7 +2017,7 @@ DynamicList.prototype.getLikeIdentifier = function(record) {
};

DynamicList.prototype.setupLikeButton = function(options) {
if (!_.get(this.data, 'social.likes')) {
if (!(this.data.social && this.data.social.likes)) {
return Promise.resolve();
}

Expand Down Expand Up @@ -2194,7 +2199,7 @@ DynamicList.prototype.getBookmarkIdentifier = function(record) {
};

DynamicList.prototype.setupBookmarkButton = function(options) {
if (!_.get(this.data, 'social.bookmark')) {
if (!(this.data.social && this.data.social.bookmark)) {
return Promise.resolve();
}

Expand Down Expand Up @@ -2335,6 +2340,7 @@ DynamicList.prototype.addDetailViewData = function(entry) {
return entry;
}

entry = _this.addPermissions(entry);
entry.entryDetails = [];

// Define detail view data based on user's settings
Expand Down Expand Up @@ -2575,7 +2581,7 @@ DynamicList.prototype.getCommentIdentifier = function(record) {
};

DynamicList.prototype.getEntryComments = function(options) {
if (!_.get(this.data, 'social.comments')) {
if (!(this.data.social && this.data.social.comments)) {
return Promise.resolve();
}

Expand Down Expand Up @@ -2637,7 +2643,7 @@ DynamicList.prototype.connectToUsersDataSource = function() {
};

DynamicList.prototype.updateCommentCounter = function(options) {
if (!_.get(this.data, 'social.comments')) {
if (!(this.data.social && this.data.social.comments)) {
return;
}

Expand Down Expand Up @@ -2697,7 +2703,7 @@ DynamicList.prototype.showComments = function(id, commentId) {
var newDate = new Date(entry.createdAt);
var timeInMilliseconds = newDate.getTime();
var userName = _.compact(_.map(_this.data.userNameFields, function(name) {
return _.get(entry, 'data.settings.user.' + name);
return entry.data && entry.data.settings && entry.data.settings.user && entry.data.settings.user[name];
})).join(' ').trim();

entryComments[index].timeInMilliseconds = timeInMilliseconds;
Expand Down Expand Up @@ -2968,7 +2974,7 @@ DynamicList.prototype.appendTempComment = function(id, value, guid, userFromData
var timestamp = (new Date()).toISOString();
var userName = _.compact(_.map(_this.data.userNameFields, function(name) {
return _this.myUserData.isSaml2
? _.get(userFromDataSource, 'data.' + name)
? userFromDataSource.data && userFromDataSource.data[name]
: _this.myUserData[name];
})).join(' ').trim();

Expand All @@ -2993,7 +2999,7 @@ DynamicList.prototype.appendTempComment = function(id, value, guid, userFromData
DynamicList.prototype.replaceComment = function(guid, commentData, context) {
var _this = this;
var userName = _.compact(_.map(_this.data.userNameFields, function(name) {
return _.get(commentData, 'data.settings.user.' + name);
return commentData.data && commentData.data.settings && commentData.data.settings.user && commentData.data.settings.user[name];
})).join(' ').trim();

if (!commentData.literalDate) {
Expand Down
Loading