-
Notifications
You must be signed in to change notification settings - Fork 547
dbeaver/pro#9798 adds sorting for columns in user tables #4484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sergeyteleshev
wants to merge
5
commits into
devel
Choose a base branch
from
9798-cb-add-ordering-for-administrative-tables
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
23381c0
dbeaver/pro#9798 adds sorting for columns in user tables
sergeyteleshev 69f2e36
dbeaver/pro#9798 adds comparator helpers
sergeyteleshev 4ff2949
dbeaver/pro#9798 moves user helpers to compareUser file
sergeyteleshev ca8fdc1
dbeaver/pro#9798 fixes naming and any
sergeyteleshev 3969177
dbeaver/pro# adds grantedUsersIdsMap to make less computations
sergeyteleshev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
webapp/packages/core-authentication/src/compareGrantSubjects.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * CloudBeaver - Cloud Database Manager | ||
| * Copyright (C) 2020-2026 DBeaver Corp and others | ||
| * | ||
| * Licensed under the Apache License, Version 2.0. | ||
| * you may not use this file except in compliance with the License. | ||
| */ | ||
| import { compareUsersByLastLogin, isUser } from './compareUser.js'; | ||
| import type { TeamInfo } from './TeamsResource.js'; | ||
| import type { AdminUser } from './UsersResource.js'; | ||
|
|
||
| export function compareGrantSubjectsByName(a: AdminUser | TeamInfo, b: AdminUser | TeamInfo): number { | ||
| const aName = isUser(a) ? a.userId : a.teamName; | ||
| const bName = isUser(b) ? b.userId : b.teamName; | ||
| return (aName ?? '').localeCompare(bName ?? ''); | ||
| } | ||
|
|
||
| export function compareGrantSubjectsByLastLogin(a: AdminUser | TeamInfo, b: AdminUser | TeamInfo): number { | ||
| return compareUsersByLastLogin( | ||
| { lastLoginTime: isUser(a) ? a.lastLoginTime : undefined }, | ||
| { lastLoginTime: isUser(b) ? b.lastLoginTime : undefined }, | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * CloudBeaver - Cloud Database Manager | ||
| * Copyright (C) 2020-2026 DBeaver Corp and others | ||
| * | ||
| * Licensed under the Apache License, Version 2.0. | ||
| * you may not use this file except in compliance with the License. | ||
| */ | ||
| import { AUTH_PROVIDER_LOCAL_ID } from './AUTH_PROVIDER_LOCAL_ID.js'; | ||
| import type { AdminUser } from './UsersResource.js'; | ||
|
|
||
| export const NEW_USER_SYMBOL = Symbol('new-user'); | ||
|
|
||
| export type AdminUserNew = AdminUser & { [NEW_USER_SYMBOL]: boolean; createdAt: number }; | ||
|
|
||
| export function isLocalUser(user: AdminUser): boolean { | ||
| return user.origins.some(origin => origin.type === AUTH_PROVIDER_LOCAL_ID); | ||
| } | ||
|
|
||
| export function isNewUser(user: AdminUser | AdminUserNew): user is AdminUserNew { | ||
| return NEW_USER_SYMBOL in user && user[NEW_USER_SYMBOL] === true && 'createdAt' in user && Boolean(user.createdAt); | ||
| } | ||
|
|
||
| export function isUser(user: unknown): user is AdminUser { | ||
| return !!user && typeof user === 'object' && 'userId' in user && 'grantedTeams' in user && 'enabled' in user; | ||
| } | ||
|
|
||
| export function compareUsersById<T extends Pick<AdminUser, 'userId'>>(a: T, b: T): number { | ||
| return a.userId.localeCompare(b.userId); | ||
| } | ||
|
|
||
| export function compareUsersByLastLogin<T extends Pick<AdminUser, 'lastLoginTime'>>(a: T, b: T): number { | ||
| const aTime = a.lastLoginTime ? new Date(a.lastLoginTime).getTime() : 0; | ||
| const bTime = b.lastLoginTime ? new Date(b.lastLoginTime).getTime() : 0; | ||
| return aTime - bTime; | ||
| } | ||
|
|
||
| export function compareUsersByNewness<T extends AdminUser>(a: T, b: T): number { | ||
| const aIsNew = isNewUser(a); | ||
| const bIsNew = isNewUser(b); | ||
|
|
||
| if (aIsNew && !bIsNew) { | ||
| return -1; | ||
| } | ||
|
|
||
| if (!aIsNew && bIsNew) { | ||
| return 1; | ||
| } | ||
|
|
||
| if (aIsNew && bIsNew) { | ||
| return b.createdAt - a.createdAt; | ||
| } | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so for every single compare we do 2 x O(n) searches among grantedUsers.
It might be a problem on big lists.
Let's optimize it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in data structure & algorithms world 2 * O(N) = O(N) and its fine. computers and browsers can handle that easy peasy
I think this matters only if you develop search engine or computer chip architecture or something like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but how the compare function is used?
it's basically O(n) * compare (O(n))