Look permissions up by name directly

selfPermissionValue scanned every permission the server lists, several
times per context menu. The model now keeps a name index next to the
id one. Also drops primaryServerGroupName, which nothing calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-25 10:38:53 +00:00
parent 67f8f46cab
commit 8c735a05b8

View File

@@ -27,6 +27,7 @@ public final class ServerModel {
* advances it. * advances it.
*/ */
private final Map<Integer, String> permissionNames = new LinkedHashMap<>(); private final Map<Integer, String> permissionNames = new LinkedHashMap<>();
private final Map<String, Integer> permissionIds = new HashMap<>();
private static final int FIRST_PERMISSION_ID = 1; private static final int FIRST_PERMISSION_ID = 1;
private int nextPermissionId = FIRST_PERMISSION_ID; private int nextPermissionId = FIRST_PERMISSION_ID;
/** Permission id -> the local client's resolved value, from {@code notifyclientneededpermissions}. */ /** Permission id -> the local client's resolved value, from {@code notifyclientneededpermissions}. */
@@ -41,6 +42,7 @@ public final class ServerModel {
serverGroups.clear(); serverGroups.clear();
channelGroups.clear(); channelGroups.clear();
permissionNames.clear(); permissionNames.clear();
permissionIds.clear();
nextPermissionId = FIRST_PERMISSION_ID; nextPermissionId = FIRST_PERMISSION_ID;
selfPermissionValues.clear(); selfPermissionValues.clear();
defaultChannelGroupId = 0; defaultChannelGroupId = 0;
@@ -94,13 +96,6 @@ public final class ServerModel {
return names; return names;
} }
/** Primary (first) server-group name for compact display, or {@code null}. */
public synchronized String primaryServerGroupName(int[] ids) {
if (ids == null || ids.length == 0) return null;
Group g = serverGroups.get(ids[0]);
return g == null ? null : g.name;
}
/** Regular (non-template, non-query) server groups, ordered for display. */ /** Regular (non-template, non-query) server groups, ordered for display. */
public synchronized List<Group> allServerGroups() { public synchronized List<Group> allServerGroups() {
return regularGroups(serverGroups); return regularGroups(serverGroups);
@@ -126,6 +121,7 @@ public final class ServerModel {
public synchronized void putPermissionName(String name) { public synchronized void putPermissionName(String name) {
if (name == null || name.isEmpty()) return; if (name == null || name.isEmpty()) return;
permissionNames.put(nextPermissionId, name); permissionNames.put(nextPermissionId, name);
permissionIds.putIfAbsent(name, nextPermissionId);
nextPermissionId++; nextPermissionId++;
} }
@@ -150,13 +146,9 @@ public final class ServerModel {
* never reported a non-default value for it). * never reported a non-default value for it).
*/ */
public synchronized int selfPermissionValue(String name) { public synchronized int selfPermissionValue(String name) {
for (Map.Entry<Integer, String> entry : permissionNames.entrySet()) { Integer id = permissionIds.get(name);
if (entry.getValue().equals(name)) { Integer value = id == null ? null : selfPermissionValues.get(id);
Integer value = selfPermissionValues.get(entry.getKey()); return value == null ? 0 : value;
if (value != null) return value;
}
}
return 0;
} }
// ---- what the local client may do ---- // ---- what the local client may do ----