feat: improve performance by only loading done backlog on demand

This commit is contained in:
Johannes Millan 2017-11-24 15:11:30 +01:00
parent 2b0098612f
commit 05eb12b062
4 changed files with 37 additions and 15 deletions

View file

@ -20,7 +20,6 @@
])
.constant('ON_DEMAND_LS_FIELDS', [
'doneBacklogTasks',
'backlogTasks',
])
.constant('TMP_FIELDS', [
'$$hashKey',
@ -60,6 +59,7 @@
},
tasks: [],
backlogTasks: [],
doneBacklogTasks:[],
distractions: [],
projects: [],
globalLinks: [],

View file

@ -42,6 +42,7 @@
vm.restoreTask = (task) => {
Tasks.moveTaskFromDoneBackLogToToday(task);
vm.doneBacklogTasks = Tasks.getDoneBacklog();
};
}
})();

View file

@ -15,6 +15,7 @@
/* @ngInject */
constructor(LS_DEFAULTS, SAVE_APP_STORAGE_POLL_INTERVAL, TMP_FIELDS, $interval, $rootScope, ON_DEMAND_LS_FIELDS, ON_DEMAND_LS_FIELDS_FOR_PROJECT, IS_ELECTRON) {
this.PROJECTS_KEY = 'projects';
this.BACKLOG_TASKS_KEY = 'doneBacklogTasks';
this.LS_DEFAULTS = LS_DEFAULTS;
this.TMP_FIELDS = TMP_FIELDS;
this.SAVE_APP_STORAGE_POLL_INTERVAL = SAVE_APP_STORAGE_POLL_INTERVAL;
@ -70,6 +71,8 @@
// also add projects data
data[this.PROJECTS_KEY] = this.getProjects();
// also add backlog tasks
data[this.BACKLOG_TASKS_KEY] = this.getDoneBacklogTasks();
fs.writeFile(path, JSON.stringify(data), function(err) {
if (err) {
@ -90,14 +93,26 @@
getCurrentAppState() {
const currentState = {};
for (let key in this.LS_DEFAULTS) {
const isNoTmpField = this.TMP_FIELDS.indexOf(key) === -1;
if (this.LS_DEFAULTS.hasOwnProperty(key) && isNoTmpField && key !== this.PROJECTS_KEY) {
const isNoTmpField = (this.TMP_FIELDS.indexOf(key) === -1);
const isNoOnDemand = (this.ON_DEMAND_LS_FIELDS.indexOf(key) === -1);
const isNotProjects = (key !== this.PROJECTS_KEY);
if (this.LS_DEFAULTS.hasOwnProperty(key) && isNoOnDemand && isNoTmpField && isNotProjects) {
currentState[key] = this.$rootScope.r[key];
}
}
return currentState;
}
getDoneBacklogTasks() {
return this.getLsItem(this.BACKLOG_TASKS_KEY);
}
saveDoneBacklogTasks(doneBacklogTasks) {
if (Array.isArray(doneBacklogTasks)) {
this.saveLsItem(doneBacklogTasks, this.BACKLOG_TASKS_KEY)
}
}
saveToLs() {
const currentState = this.getCurrentAppState();
for (let key in currentState) {

View file

@ -19,7 +19,7 @@
/* @ngInject */
class Tasks {
constructor(Uid, $rootScope, Dialogs, IS_ELECTRON, ShortSyntax, TasksUtil, Jira, TakeABreakReminder, SimpleToast) {
constructor(Uid, $rootScope, Dialogs, IS_ELECTRON, ShortSyntax, TasksUtil, Jira, TakeABreakReminder, SimpleToast, AppStorage) {
this.$rootScope = $rootScope;
this.Uid = Uid;
this.$rootScope = $rootScope;
@ -29,6 +29,7 @@
this.IS_ELECTRON = IS_ELECTRON;
this.SimpleToast = SimpleToast;
this.Jira = Jira;
this.AppStorage = AppStorage;
// SETUP HANDLERS FOR ELECTRON EVENTS
if (IS_ELECTRON) {
@ -120,7 +121,7 @@
// we want the current task to be a reference to the tasks array
if (this.$rootScope.r.currentTask) {
currentTask = _.find(this.$rootScope.r.tasks, (task) => {
if (task.subTasks && task.subTasks.length > 0) {
if (task.subTasks && task.subTasks.length > 0) {
let subTaskMatchTmp = _.find(task.subTasks, { id: this.$rootScope.r.currentTask.id });
if (subTaskMatchTmp) {
subTaskMatch = subTaskMatchTmp;
@ -134,8 +135,10 @@
return this.$rootScope.r.currentTask;
}
// NOTE: doneBacklogTasks can't be really updated when accessed withthis
getById(taskId) {
return _.find(this.$rootScope.r.tasks, ['id', taskId]) || _.find(this.$rootScope.r.backlogTasks, ['id', taskId]) || _.find(this.$rootScope.r.doneBacklogTasks, ['id', taskId]);
const doneBacklogTasks = this.getDoneBacklog();
return _.find(this.$rootScope.r.tasks, ['id', taskId]) || _.find(this.$rootScope.r.backlogTasks, ['id', taskId]) || _.find(doneBacklogTasks, ['id', taskId]);
}
isTaskWithOriginalIdExistant(originalId) {
@ -150,9 +153,10 @@
}
getDoneBacklog() {
this.TasksUtil.checkDupes(this.$rootScope.r.doneBacklogTasks);
this.TasksUtil.convertDurationStringsToMomentForList(this.$rootScope.r.doneBacklogTasks);
return this.$rootScope.r.doneBacklogTasks;
const doneBacklogTasks = this.AppStorage.getDoneBacklogTasks();
this.TasksUtil.checkDupes(doneBacklogTasks);
this.TasksUtil.convertDurationStringsToMomentForList(doneBacklogTasks);
return doneBacklogTasks;
}
getToday() {
@ -601,7 +605,9 @@
moveTaskFromDoneBackLogToToday(task) {
task.isDone = false;
this.moveTask(task, this.$rootScope.r.doneBacklogTasks, this.$rootScope.r.tasks);
const doneBacklogTasks = this.getDoneBacklog();
this.moveTask(task, doneBacklogTasks, this.$rootScope.r.tasks);
this.AppStorage.saveDoneBacklogTasks(doneBacklogTasks);
this.SimpleToast('SUCCESS', 'Restored task "' + task.title + '" from done backlog.');
}
@ -619,19 +625,19 @@
}
updateDoneBacklog(tasks) {
this.$rootScope.r.doneBacklogTasks = tasks;
this.AppStorage.saveDoneBacklogTasks(tasks);
}
clearBacklog() {
// we want to keep the original reference intact so we use length
// @see: http://stackoverflow.com/questions/1232040/how-do-i-empty-an-array-in-javascript
this.$rootScope.r.backlogTasks.length = 0;
this.AppStorage.saveDoneBacklogTasks([]);
this.SimpleToast('SUCCESS', 'Backlog deleted!');
}
addDoneTasksToDoneBacklog() {
let doneTasks = this.getDoneToday().slice(0);
this.$rootScope.r.doneBacklogTasks = doneTasks.concat(this.$rootScope.r.doneBacklogTasks);
const currentDoneBacklogTasks = this.getDoneBacklog();
const mewDoneBacklogTasks = doneTasks.concat(currentDoneBacklogTasks);
this.AppStorage.saveDoneBacklogTasks(mewDoneBacklogTasks);
}
// SPECIAL METHODS