Skip to content
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

[Server v3] Sort, cleanup and uniformise SQL queries #7122

Open
vxgmichel opened this issue Apr 19, 2024 · 0 comments
Open

[Server v3] Sort, cleanup and uniformise SQL queries #7122

vxgmichel opened this issue Apr 19, 2024 · 0 comments
Labels
A-Server Area: Server application I-Postgresql Impact: Postgresql issue refactor Improve code, don't change behavior

Comments

@vxgmichel
Copy link
Contributor

A cleanup of the SQL queries could be useful, in particular:

  • check that consistent naming is used
  • check that selected columns are actually used by the code
  • see if some queries overlap

Some queries are also duplicated in different component modules. Instead, one component should probably expose a method to be used by the other components.

Another improvement would be to replace all the occurrences of such pattern:

FROM realm_topic
WHERE realm = { q_realm_internal_id(organization_id="$organization_id", realm_id="$realm_id") }

by:

FROM realm_topic
JOIN realm ON realm_topic.realm = realm._id
JOIN organization ON realm.organization = organization._id
WHERE realm.realm_id = $realm_id
AND organization.organization_id = $organization_id

At the moment both approaches are used, so it's a bit confusing to navigate between queries.

Another suggestion: internal ids for organization, user and device could be extracted during the checks common to all authenticated commands (see #7119 ). The same could also performed for the internal realm id for the realm commands. This would simplify a lot of SQL queries like the example above. There was already an attempt at implementing this here:

@dataclass
class AnonymousAuthInfo:
organization_id: OrganizationID
organization_internal_id: int
@dataclass
class InvitedAuthInfo:
organization_id: OrganizationID
token: InvitationToken
type: InvitationType
organization_internal_id: int
invitation_internal_id: int
@dataclass
class AuthenticatedAuthInfo:
organization_id: OrganizationID
device_id: DeviceID
device_verify_key: VerifyKey
organization_internal_id: int
device_internal_id: int

@mmmarcos mmmarcos added I-Postgresql Impact: Postgresql issue A-Server Area: Server application refactor Improve code, don't change behavior labels Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Server Area: Server application I-Postgresql Impact: Postgresql issue refactor Improve code, don't change behavior
Projects
None yet
Development

No branches or pull requests

2 participants