Merge pull request #20171 from gustavotrott/client-settings-cache-system

enhancement: Speed up the client loading (by implementing a cache system to obtain ClientSettings)
This commit is contained in:
Anton Georgiev 2024-05-03 15:55:07 -04:00 committed by GitHub
commit 8db5b74c44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 114 additions and 109 deletions

View File

@ -1,24 +0,0 @@
location /graphql-test {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
# Websocket connection
location /v1/graphql {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
#proxy_pass http://127.0.0.1:8080; #Hasura
proxy_pass http://127.0.0.1:8378; #Graphql Middleware
}
location /api/rest {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080; #Hasura
}

View File

@ -1,23 +0,0 @@
location /graphql-test {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
# Websocket connection
location /v1/graphql {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080; #Hasura
}
location /api/rest {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080; #Hasura
}

View File

@ -59,6 +59,13 @@ type Mutation {
): Boolean ): Boolean
} }
type Mutation {
captionSetOwner(
locale: String!
ownerUserId: String!
): Boolean
}
type Mutation { type Mutation {
captionSubmitText( captionSubmitText(
transcriptId: String! transcriptId: String!
@ -562,11 +569,3 @@ input GuestUserApprovalStatus {
status: String! status: String!
} }
type Mutation {
captionSetOwner(
locale: String!
ownerUserId: String!
): Boolean
}

View File

@ -59,6 +59,12 @@ actions:
handler: '{{HASURA_BBB_GRAPHQL_ACTIONS_ADAPTER_URL}}' handler: '{{HASURA_BBB_GRAPHQL_ACTIONS_ADAPTER_URL}}'
permissions: permissions:
- role: bbb_client - role: bbb_client
- name: captionSetOwner
definition:
kind: synchronous
handler: '{{HASURA_BBB_GRAPHQL_ACTIONS_ADAPTER_URL}}'
permissions:
- role: bbb_client
- name: captionSubmitText - name: captionSubmitText
definition: definition:
kind: synchronous kind: synchronous
@ -493,12 +499,6 @@ actions:
handler: '{{HASURA_BBB_GRAPHQL_ACTIONS_ADAPTER_URL}}' handler: '{{HASURA_BBB_GRAPHQL_ACTIONS_ADAPTER_URL}}'
permissions: permissions:
- role: bbb_client - role: bbb_client
- name: captionSetOwner
definition:
kind: synchronous
handler: '{{HASURA_BBB_GRAPHQL_ACTIONS_ADAPTER_URL}}'
permissions:
- role: bbb_client
custom_types: custom_types:
enums: [] enums: []
input_objects: input_objects:

View File

@ -32,3 +32,10 @@
clientLog: clientSettingsJson(path: "$.public.clientLog") clientLog: clientSettingsJson(path: "$.public.clientLog")
} }
} }
- name: clientSettings
query: |
query clientStartupSettings {
meeting_clientSettings {
clientSettingsJson
}
}

View File

@ -1,3 +1,12 @@
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: clientSettings
methods:
- GET
name: clientSettings
url: clientSettings
- comment: "" - comment: ""
definition: definition:
query: query:

View File

@ -60,10 +60,9 @@ const StartupDataFetch: React.FC<StartupDataFetchProps> = ({
setLoading(false); setLoading(false);
return; return;
} }
const clientStartupSettings = '/api/rest/clientStartupSettings/'; const clientStartupSettings = `/api/rest/clientStartupSettings/?sessionToken=${sessionToken}`;
const url = new URL(`${window.location.origin}${clientStartupSettings}`); const url = new URL(`${window.location.origin}${clientStartupSettings}`);
const headers = new Headers({ 'X-Session-Token': sessionToken, 'Content-Type': 'application/json' }); fetch(url, { method: 'get' })
fetch(url, { method: 'get', headers })
.then((resp) => resp.json()) .then((resp) => resp.json())
.then((data: Response) => { .then((data: Response) => {
const settings = data.meeting_clientSettings[0]; const settings = data.meeting_clientSettings[0];

View File

@ -1,6 +1,4 @@
import React, { useContext, useEffect } from 'react'; import React, { useContext, useEffect } from 'react';
import { useQuery } from '@apollo/client';
import { getBigBlueButtonSettings, getBigBlueButtonSettingsResponse } from './queries';
import { setMeetingSettings } from '../../core/local-states/useMeetingSettings'; import { setMeetingSettings } from '../../core/local-states/useMeetingSettings';
import MeetingClientSettings from '../../Types/meetingClientSettings'; import MeetingClientSettings from '../../Types/meetingClientSettings';
import ClientStartup from '/client/clientStartup'; import ClientStartup from '/client/clientStartup';
@ -8,6 +6,12 @@ import { LoadingContext } from '../common/loading-screen/loading-screen-HOC/comp
import CustomUsersSettings from '../join-handler/custom-users-settings/component'; import CustomUsersSettings from '../join-handler/custom-users-settings/component';
import logger from '/imports/startup/client/logger'; import logger from '/imports/startup/client/logger';
interface Response {
meeting_clientSettings: Array<{
clientSettingsJson: MeetingClientSettings,
}>
}
declare global { declare global {
interface Window { interface Window {
meetingClientSettings: MeetingClientSettings; meetingClientSettings: MeetingClientSettings;
@ -15,7 +19,6 @@ declare global {
} }
const SettingsLoader: React.FC = () => { const SettingsLoader: React.FC = () => {
const { loading, error, data } = useQuery<getBigBlueButtonSettingsResponse>(getBigBlueButtonSettings);
const [allowToRender, setAllowToRender] = React.useState(false); const [allowToRender, setAllowToRender] = React.useState(false);
const loadingContextInfo = useContext(LoadingContext); const loadingContextInfo = useContext(LoadingContext);
useEffect(() => { useEffect(() => {
@ -24,22 +27,26 @@ const SettingsLoader: React.FC = () => {
}, []); }, []);
useEffect(() => { useEffect(() => {
if (!loading && !error) { const urlParams = new URLSearchParams(window.location.search);
const settings = data?.meeting[0].clientSettings.clientSettingsJson; const sessionToken = urlParams.get('sessionToken');
if (settings && Object.keys(settings).length > 0) { const clientStartupSettings = `/api/rest/clientSettings/?sessionToken=${sessionToken}`;
const url = new URL(`${window.location.origin}${clientStartupSettings}`);
fetch(url, { method: 'get' })
.then((resp) => resp.json())
.then((data: Response) => {
const settings = data?.meeting_clientSettings[0].clientSettingsJson;
window.meetingClientSettings = JSON.parse(JSON.stringify(settings as unknown as MeetingClientSettings)); window.meetingClientSettings = JSON.parse(JSON.stringify(settings as unknown as MeetingClientSettings));
const Meteor = { settings: {} }; const Meteor = { settings: {} };
Meteor.settings = window.meetingClientSettings; Meteor.settings = window.meetingClientSettings;
setMeetingSettings(settings as unknown as MeetingClientSettings); setMeetingSettings(settings as unknown as MeetingClientSettings);
setAllowToRender(true); setAllowToRender(true);
} }).catch(() => {
} loadingContextInfo.setLoading(false, '');
}, [loading]); throw new Error('Error on requesting client settings data.');
if (loading) return null; });
if (error) { // }
loadingContextInfo.setLoading(false, ''); }, []);
throw new Error('Error on requesting meeting settings data: ', error);
}
return ( return (
(allowToRender) (allowToRender)
? ( ? (

View File

@ -1,27 +0,0 @@
import { gql } from '@apollo/client';
export interface getBigBlueButtonSettingsResponse {
meeting: Meeting[]
}
interface ClientSettings {
clientSettingsJson: string; // You might need to adjust the type based on the actual JSON structure
}
interface Meeting {
clientSettings: ClientSettings;
}
export const getBigBlueButtonSettings = gql`
query getClientSettings {
meeting {
clientSettings {
clientSettingsJson
}
}
}
`;
export default {
getBigBlueButtonSettings,
};

View File

@ -0,0 +1 @@
proxy_cache_path /tmp/hasura-client-settings-cache levels=1:2 keys_zone=client_settings_cache:64m inactive=2880m use_temp_path=off;

View File

@ -28,12 +28,15 @@ echo "Build of bbb-graphql-middleware finished"
cp bbb-graphql-middleware staging/usr/local/bin/bbb-graphql-middleware cp bbb-graphql-middleware staging/usr/local/bin/bbb-graphql-middleware
mkdir -p staging/etc/nginx/conf.d
cp bbb-graphql-client-settings-cache.conf staging/etc/nginx/conf.d
# Create service bbb-graphql-middleware # Create service bbb-graphql-middleware
cp ./bbb-graphql-middleware-config.env staging/etc/default/bbb-graphql-middleware cp bbb-graphql-middleware-config.env staging/etc/default/bbb-graphql-middleware
cp ./bbb-graphql-middleware.service staging/lib/systemd/system/bbb-graphql-middleware.service cp bbb-graphql-middleware.service staging/lib/systemd/system/bbb-graphql-middleware.service
# Set nginx location # Set nginx location
cp ./graphql.nginx staging/usr/share/bigbluebutton/nginx cp graphql.nginx staging/usr/share/bigbluebutton/nginx
. ./opts-$DISTRO.sh . ./opts-$DISTRO.sh

View File

@ -0,0 +1,54 @@
location /graphql-test {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
# Websocket connection
location /v1/graphql {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
#proxy_pass http://127.0.0.1:8080; #Hasura
proxy_pass http://127.0.0.1:8378; #Graphql Middleware
}
location /api/rest {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080; #Hasura
}
#Set cache system for client settings
location ~ ^/api/rest/(clientStartupSettings|clientSettings)/ {
#Store URL sessionToken once it will be injected as a header X-Session-Token
set $session_token "";
if ($args ~* "(?:^|&)sessionToken=([^&]+)") {
set $session_token $1;
}
auth_request /bigbluebutton/connection/checkAuthorization;
auth_request_set $meeting_id $sent_http_meeting_id;
#Remove sessionToken from URL once Hasura doesn't expect to receive it
if ($args ~* "^(.*&)?sessionToken=[^&]*(.*)$") {
set $args $1$2;
}
proxy_set_header x-session-token $session_token;
proxy_cache client_settings_cache;
proxy_cache_key "$request_uri|$meeting_id";
proxy_cache_use_stale updating;
proxy_cache_valid 24h;
proxy_cache_lock on;
add_header X-Cached $upstream_cache_status;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080; #Hasura
}

View File

@ -31,7 +31,7 @@ cp -r hasura-graphql staging/usr/local/bin/hasura-graphql-engine
cp -r hasura-config.env staging/etc/default/bbb-graphql-server cp -r hasura-config.env staging/etc/default/bbb-graphql-server
cp -r bbb_schema.sql metadata config.yaml staging/usr/share/bbb-graphql-server cp -r bbb_schema.sql metadata config.yaml staging/usr/share/bbb-graphql-server
cp ./bbb-graphql-server.service staging/lib/systemd/system/bbb-graphql-server.service cp bbb-graphql-server.service staging/lib/systemd/system/bbb-graphql-server.service
mkdir -p hasura-cli mkdir -p hasura-cli
cd hasura-cli cd hasura-cli