Skip to content

Commit

Permalink
Support team backups in packed format
Browse files Browse the repository at this point in the history
Team backup/restore was previously always unpacked, which is good for
readability but bad for memory usage. At high team counts, this can be a
serious problem, so with this change, if you have more than 350 teams,
your teams will be backed up in packed format.
  • Loading branch information
Zarel committed Aug 28, 2018
1 parent 9d17e2b commit 28aa6e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion js/client-teambuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@
buf += '<div class="teamedit"><textarea readonly class="textbox" rows="17">' + Tools.escapeHTML(Storage.exportFolder(this.curFolder)) + '</textarea></div>';
} else {
buf = '<div class="pad"><button name="back"><i class="fa fa-chevron-left"></i> List</button> <button name="saveBackup" class="savebutton"><i class="fa fa-floppy-o"></i> Save</button></div>';
buf += '<div class="teamedit"><textarea class="textbox" rows="17">' + Tools.escapeHTML(Storage.exportAllTeams()) + '</textarea></div>';
buf += '<div class="teamedit"><textarea class="textbox" rows="17">';
if (Storage.teams.length > 350) {
buf += Tools.escapeHTML(Storage.getPackedTeams());
} else {
buf += Tools.escapeHTML(Storage.exportAllTeams());
}
buf += '</textarea></div>';
}
this.$el.html(buf);
this.$('.teamedit textarea').focus().select();
Expand Down
10 changes: 7 additions & 3 deletions js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1022,9 +1022,9 @@ Storage.getPackedTeam = function (team) {
return team.team;
};

Storage.importTeam = function (text, teams) {
var text = text.split("\n");
var team = [];
Storage.importTeam = function (buffer, teams) {
var text = buffer.split("\n");
var team = teams ? null : [];
var curSet = null;
if (teams === true) {
Storage.teams = [];
Expand Down Expand Up @@ -1062,6 +1062,10 @@ Storage.importTeam = function (text, teams) {
folder: folder,
iconCache: ''
});
} else if (!team) {
// not in backup format
Storage.teams = Storage.unpackAllTeams(buffer);
return;
} else if (!curSet) {
curSet = {name: '', species: '', gender: ''};
team.push(curSet);
Expand Down

0 comments on commit 28aa6e8

Please sign in to comment.