UBERF-7595: Do not use /api/v1/version on connect (#6075)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2024-07-16 16:39:42 +07:00 committed by GitHub
parent d6eaaa9f01
commit 2b3caf6283
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 46 additions and 92 deletions

View File

@ -269,6 +269,10 @@ export async function createClient (
const oldOnConnect: ((event: ClientConnectEvent) => Promise<void>) | undefined = conn.onConnect
conn.onConnect = async (event) => {
console.log('Client: onConnect', event)
if (event === ClientConnectEvent.Maintenance) {
await oldOnConnect?.(ClientConnectEvent.Maintenance)
return
}
// Find all new transactions and apply
const loadModelResponse = await ctx.with(
'connect',

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
import notification, { type DocNotifyContext } from '@hcengineering/notification'
import notification, { type DocNotifyContext, type InboxNotification } from '@hcengineering/notification'
import {
generateId,
type Ref,
@ -409,7 +409,7 @@ export async function removeActivityChannels (contexts: DocNotifyContext[]): Pro
const notifications = notificationsByContext.get(context._id) ?? []
await client.archiveNotifications(
ops,
notifications.map(({ _id }) => _id)
notifications.map(({ _id }: InboxNotification) => _id)
)
await ops.remove(context)
}

View File

@ -55,10 +55,6 @@ export async function connect (title: string): Promise<Client | undefined> {
_token = token
let version: Version | undefined
let serverEndpoint = endpoint.replace(/^ws/g, 'http')
if (serverEndpoint.endsWith('/')) {
serverEndpoint = serverEndpoint.substring(0, serverEndpoint.length - 1)
}
const clientFactory = await getResource(client.function.GetClient)
_client = await clientFactory(
token,
@ -98,21 +94,15 @@ export async function connect (title: string): Promise<Client | undefined> {
location.reload()
versionError.set(`${currentVersionStr} != ${reconnectVersionStr}`)
}
const serverVersion: { version: string } = await (
await fetch(serverEndpoint + '/api/v1/version', {})
).json()
console.log('Server version', serverVersion.version)
if (serverVersion.version !== '' && serverVersion.version !== currentVersionStr) {
console.log('Server version', reconnectVersionStr)
if (reconnectVersionStr !== '' && reconnectVersionStr !== currentVersionStr) {
if (typeof sessionStorage !== 'undefined') {
if (sessionStorage.getItem(versionStorageKey) !== serverVersion.version) {
sessionStorage.setItem(versionStorageKey, serverVersion.version)
if (sessionStorage.getItem(versionStorageKey) !== reconnectVersionStr) {
sessionStorage.setItem(versionStorageKey, reconnectVersionStr)
location.reload()
}
} else {
location.reload()
}
versionError.set(`${currentVersionStr} => ${serverVersion.version}`)
versionError.set(`${currentVersionStr} => ${reconnectVersionStr}`)
}
}
})()
@ -146,23 +136,6 @@ export async function connect (title: string): Promise<Client | undefined> {
return undefined
}
}
try {
const serverVersion: { version: string } = await (await fetch(serverEndpoint + '/api/v1/version', {})).json()
console.log('Server version', serverVersion.version, version !== undefined ? versionToString(version) : '')
if (
serverVersion.version !== '' &&
(version === undefined || serverVersion.version !== versionToString(version))
) {
const versionStr = version !== undefined ? versionToString(version) : 'unknown'
versionError.set(`${versionStr} => ${serverVersion.version}`)
return
}
} catch (err: any) {
versionError.set('server version not available')
return
}
} catch (err: any) {
Analytics.handleError(err)
console.error(err)

View File

@ -132,12 +132,8 @@ export async function connect (title: string): Promise<Client | undefined> {
}
_token = token
let version: Version | undefined
let serverEndpoint = endpoint.replace(/^ws/g, 'http')
if (serverEndpoint.endsWith('/')) {
serverEndpoint = serverEndpoint.substring(0, serverEndpoint.length - 1)
}
const clientFactory = await getResource(client.function.GetClient)
let version: Version | undefined
const newClient = await ctx.with(
'create-client',
{},
@ -195,29 +191,21 @@ export async function connect (title: string): Promise<Client | undefined> {
location.reload()
versionError.set(`${currentVersionStr} != ${reconnectVersionStr}`)
}
const serverVersion: { version: string } = await ctx.with(
'fetch-server-version',
{},
async () => await (await fetch(serverEndpoint + '/api/v1/version', {})).json()
)
console.log(
'Server version',
serverVersion.version,
reconnectVersionStr,
version !== undefined ? versionToString(version) : ''
)
if (serverVersion.version !== '' && serverVersion.version !== currentVersionStr) {
if (reconnectVersionStr !== '' && currentVersionStr !== reconnectVersionStr) {
if (typeof sessionStorage !== 'undefined') {
if (sessionStorage.getItem(versionStorageKey) !== serverVersion.version) {
sessionStorage.setItem(versionStorageKey, serverVersion.version)
if (sessionStorage.getItem(versionStorageKey) !== reconnectVersionStr) {
sessionStorage.setItem(versionStorageKey, reconnectVersionStr)
location.reload()
}
} else {
location.reload()
}
versionError.set(`${currentVersionStr} => ${serverVersion.version}`)
} else {
versionError.set(undefined)
versionError.set(`${currentVersionStr} != ${reconnectVersionStr}`)
}
}
})()
@ -276,27 +264,6 @@ export async function connect (title: string): Promise<Client | undefined> {
return undefined
}
}
try {
const serverVersion: { version: string } = await ctx.with(
'find-server-version',
{},
async () => await (await fetch(serverEndpoint + '/api/v1/version', {})).json()
)
console.log('Server version', serverVersion.version, version !== undefined ? versionToString(version) : '')
if (
serverVersion.version !== '' &&
(version === undefined || serverVersion.version !== versionToString(version))
) {
const versionStr = version !== undefined ? versionToString(version) : 'unknown'
versionError.set(`${versionStr} => ${serverVersion.version}`)
return
}
} catch (err: any) {
versionError.set('server version not available')
return
}
} catch (err: any) {
console.error(err)
Analytics.handleError(err)

View File

@ -221,25 +221,35 @@ class TSessionManager implements SessionManager {
@withContext('get-workspace-info')
async getWorkspaceInfo (ctx: MeasureContext, accounts: string, token: string): Promise<WorkspaceLoginInfo> {
const userInfo = await (
await fetch(accounts, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
},
body: JSON.stringify({
method: 'getWorkspaceInfo',
params: [true]
})
})
).json()
if (userInfo.error !== undefined) {
ctx.error('Error response from account service', { error: JSON.stringify(userInfo) })
throw new Error(JSON.stringify(userInfo.error))
}
for (let i = 0; i < 10; i++) {
try {
const userInfo = await (
await fetch(accounts, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
},
body: JSON.stringify({
method: 'getWorkspaceInfo',
params: [true]
})
})
).json()
return { ...userInfo.result, upgrade: userInfo.upgrade }
if (userInfo.error !== undefined) {
ctx.error('Error response from account service', { error: JSON.stringify(userInfo) })
throw new Error(JSON.stringify(userInfo.error))
}
return { ...userInfo.result, upgrade: userInfo.upgrade }
} catch (err: any) {
if (i === 9) {
throw err
}
await new Promise<void>((resolve) => setTimeout(resolve, 100))
}
}
throw new Error('')
}
@withContext('📲 add-session')