DEV: Use Category.findById instead of Array.find (#26445)

Category.findById uses a Map to look up categories by ID which makes it
faster and preferable over Site.categories.find.
This commit is contained in:
Bianca Nenciu
2024-04-03 15:51:05 +03:00
committed by GitHub
parent ff6cb1bc05
commit b09558ae2d
6 changed files with 15 additions and 22 deletions

View File

@ -8,6 +8,7 @@ import { isBlank, isPresent } from "@ember/utils";
import { ajax } from "discourse/lib/ajax";
import { extractError } from "discourse/lib/ajax-error";
import { escapeExpression } from "discourse/lib/utilities";
import Category from "discourse/models/category";
import discourseDebounce from "discourse-common/lib/debounce";
import I18n from "discourse-i18n";
@ -67,9 +68,7 @@ export default class ChatModalCreateChannel extends Component {
@action
onCategoryChange(categoryId) {
const category = categoryId
? this.site.categories.findBy("id", categoryId)
: null;
const category = categoryId ? Category.findById(categoryId) : null;
this.#updatePermissionsHint(category);
const name = this.name || category?.name || "";