From 2cc6e70b0baa4cac1e4b92462471d4546e3456b8 Mon Sep 17 00:00:00 2001
From: David Hirtle
Date: Sat, 20 Oct 2012 21:06:03 -0700
Subject: [PATCH] Do not iterate over closed issues unless user really cares;
huge perf boost
---
public/js/IssueManager.js | 49 ++++++++++++++++++++++++++++-----------
views/project.html | 2 +-
2 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/public/js/IssueManager.js b/public/js/IssueManager.js
index 70cd535..48da8f9 100644
--- a/public/js/IssueManager.js
+++ b/public/js/IssueManager.js
@@ -5,17 +5,25 @@ define([
function IssueManager(socket) {
this.socket = socket;
- this.allIssues = ko.observableArray();
+ this.openIssues = ko.observableArray();
+ this.closedIssues = ko.observableArray();
+ this.allIssues = ko.computed(function () {
+ return this.openIssues().concat(this.closedIssues());
+ }, this);
this.tagFilters = ko.observableArray();
-
this.showClosed = ko.observable(false);
- this.showClosed.subscribe(this.filterIssueList, this);
- this.sortedIssues = ko.computed(function () {
- return this.allIssues().sort(Issue.sort);
+ this.displayedIssues = ko.computed(function () {
+ if (!this.showClosed()) {
+ return this.openIssues().sort(Issue.sort);
+ } else {
+ return this.allIssues().sort(Issue.sort);
+ }
}, this);
+ this.showClosed.subscribe(this.filterIssueList, this);
+
this.filteredIssuesCount = ko.computed(function () {
- return _.filter(this.sortedIssues(), function (issue) {
+ return _.filter(this.displayedIssues(), function (issue) {
return !issue.filtered();
}).length;
}, this);
@@ -27,17 +35,28 @@ define([
var that = this;
this.socket.on('issues', function (issues) {
- that.allIssues(_.map(issues, function (issue) {
- return new Issue(issue.id, issue);
- }));
- that.initTagFilters(that.allIssues());
- that.filterIssueList();
+ var mapped = _.map(issues, function (issue) {
+ return new Issue(issue.id, issue);
+ });
+ that.initTagFilters(mapped);
+ that.filterIssueList(mapped);
+
+ var open = [];
+ var closed = [];
+ _.each(mapped, function (issue) {
+ if (issue.closed()) {
+ return closed.push(issue);
+ }
+ open.push(issue);
+ });
+ that.openIssues(open);
+ that.closedIssues(closed);
});
this.socket.on('issue created', function (event) {
var newIssue = new Issue(event.details.issue.id, event.details.issue);
filterIssue(newIssue, that);
- that.allIssues.push(newIssue);
+ that.openIssues.push(newIssue);
});
this.socket.on('issue assigned', function (event) {
var issue = that.findIssue(event.details.issue.id);
@@ -134,13 +153,15 @@ define([
this.filterIssueList();
};
- IssueManager.prototype.filterIssueList = function () {
+ IssueManager.prototype.filterIssueList = function (issues) {
+ var issuesToFilter = _.isArray(issues) ? issues : this.displayedIssues();
+
var showClosed = this.showClosed();
var requiredTags = TagFilter.getOn(this.tagFilters());
var forbiddenTags = TagFilter.getOff(this.tagFilters());
var filterValue = getFilterInputValue();
- _.each(this.sortedIssues(), function (issue) {
+ _.each(issuesToFilter, function (issue) {
issue.updateFiltered(showClosed, requiredTags, forbiddenTags, filterValue);
});
};
diff --git a/views/project.html b/views/project.html
index db84188..19cf0bb 100644
--- a/views/project.html
+++ b/views/project.html
@@ -101,7 +101,7 @@ Issues No issues. w00t!
loading…
-