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.
*/
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 int nextPermissionId = FIRST_PERMISSION_ID;
/** Permission id -> the local client's resolved value, from {@code notifyclientneededpermissions}. */
@@ -41,6 +42,7 @@ public final class ServerModel {
serverGroups.clear();
channelGroups.clear();
permissionNames.clear();
permissionIds.clear();
nextPermissionId = FIRST_PERMISSION_ID;
selfPermissionValues.clear();
defaultChannelGroupId = 0;
@@ -94,13 +96,6 @@ public final class ServerModel {
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. */
public synchronized List<Group> allServerGroups() {
return regularGroups(serverGroups);
@@ -126,6 +121,7 @@ public final class ServerModel {
public synchronized void putPermissionName(String name) {
if (name == null || name.isEmpty()) return;
permissionNames.put(nextPermissionId, name);
permissionIds.putIfAbsent(name, nextPermissionId);
nextPermissionId++;
}
@@ -150,13 +146,9 @@ public final class ServerModel {
* never reported a non-default value for it).
*/
public synchronized int selfPermissionValue(String name) {
for (Map.Entry<Integer, String> entry : permissionNames.entrySet()) {
if (entry.getValue().equals(name)) {
Integer value = selfPermissionValues.get(entry.getKey());
if (value != null) return value;
}
}
return 0;
Integer id = permissionIds.get(name);
Integer value = id == null ? null : selfPermissionValues.get(id);
return value == null ? 0 : value;
}
// ---- what the local client may do ----