Skip to content

Commit

Permalink
Rewrite OC.SystemTags.getDescriptiveTag to vanilla js
Browse files Browse the repository at this point in the history
For every tag a deprecation warning is emitted.
With 10k tags the ui becomes unresponsive and inspector crashed occasionally.

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
  • Loading branch information
kesselb committed Sep 15, 2022
1 parent 1bfac6d commit 79b4c4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
19 changes: 11 additions & 8 deletions core/src/systemtags/systemtags.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,24 @@ import escapeHTML from 'escape-html'
/**
*
* @param {OC.SystemTags.SystemTagModel|Object|String} tag
* @returns {jQuery}
* @returns {HTMLElement}
*/
getDescriptiveTag: function(tag) {
if (_.isUndefined(tag.name) && !_.isUndefined(tag.toJSON)) {
tag = tag.toJSON()
}

var $span = document.createElement('span')

if (_.isUndefined(tag.name)) {
return $('<span>').addClass('non-existing-tag').text(
t('core', 'Non-existing tag #{tag}', {
$span.classList.add('non-existing-tag')
$span.textContent = t('core', 'Non-existing tag #{tag}', {
tag: tag
})
)
})
return $span
}

var $span = $('<span>')
$span.append(escapeHTML(tag.name))
$span.textContent = escapeHTML(tag.name)

var scope
if (!tag.userAssignable) {
Expand All @@ -62,7 +63,9 @@ import escapeHTML from 'escape-html'
scope = t('core', 'invisible')
}
if (scope) {
$span.append($('<em>').text(' (' + scope + ')'))
var $scope = document.createElement('em')
$scope.textContent = ' (' + scope + ')'
$span.appendChild($scope)
}
return $span
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/systemtags/systemtagsinputfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ import templateSelection from './templates/selection.handlebars'
return templateResult(_.extend({
renameTooltip: t('core', 'Rename'),
allowActions: this._allowActions,
tagMarkup: this._isAdmin ? OC.SystemTags.getDescriptiveTag(data)[0].innerHTML : null,
tagMarkup: this._isAdmin ? OC.SystemTags.getDescriptiveTag(data).innerHTML : null,
isAdmin: this._isAdmin
}, data))
},
Expand All @@ -305,7 +305,7 @@ import templateSelection from './templates/selection.handlebars'
*/
_formatSelection: function(data) {
return templateSelection(_.extend({
tagMarkup: this._isAdmin ? OC.SystemTags.getDescriptiveTag(data)[0].innerHTML : null,
tagMarkup: this._isAdmin ? OC.SystemTags.getDescriptiveTag(data).innerHTML : null,
isAdmin: this._isAdmin
}, data))
},
Expand Down

0 comments on commit 79b4c4f

Please sign in to comment.