Skip to content

Commit

Permalink
fix(server): hotfix auth & doc push (#6168)
Browse files Browse the repository at this point in the history
  • Loading branch information
forehalo authored and darkskygit committed Mar 18, 2024
1 parent 5693d90 commit a721b38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
14 changes: 1 addition & 13 deletions packages/backend/server/src/core/auth/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@nestjs/common';
import { ModuleRef, Reflector } from '@nestjs/core';

import { Config, getRequestResponseFromContext } from '../../fundamentals';
import { getRequestResponseFromContext } from '../../fundamentals';
import { AuthService, parseAuthUserSeqNum } from './service';

function extractTokenFromHeader(authorization: string) {
Expand All @@ -27,7 +27,6 @@ export class AuthGuard implements CanActivate, OnModuleInit {
private auth!: AuthService;

constructor(
private readonly config: Config,
private readonly ref: ModuleRef,
private readonly reflector: Reflector
) {}
Expand All @@ -43,17 +42,6 @@ export class AuthGuard implements CanActivate, OnModuleInit {
let sessionToken: string | undefined =
req.cookies[AuthService.sessionCookieName];

// backward compatibility for client older then 0.12
// TODO: remove
if (!sessionToken) {
sessionToken =
req.cookies[
this.config.https
? '__Secure-next-auth.session-token'
: 'next-auth.session-token'
];
}

if (!sessionToken && req.headers.authorization) {
sessionToken = extractTokenFromHeader(req.headers.authorization);
}
Expand Down
18 changes: 12 additions & 6 deletions packages/backend/server/src/core/doc/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,15 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
updates: Buffer[],
retryTimes = 10
) {
const lastSeq = await this.getUpdateSeq(workspaceId, guid, updates.length);
const now = Date.now();
let timestamp = now;
await new Promise<void>((resolve, reject) => {
const timestamp = await new Promise<number>((resolve, reject) => {
defer(async () => {
const lastSeq = await this.getUpdateSeq(
workspaceId,
guid,
updates.length
);
const now = Date.now();
let timestamp = now;
let turn = 0;
const batchCount = 10;
for (const batch of chunk(updates, batchCount)) {
Expand All @@ -303,14 +307,16 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
});
turn++;
}

return timestamp;
})
.pipe(retry(retryTimes)) // retry until seq num not conflict
.subscribe({
next: () => {
next: timestamp => {
this.logger.debug(
`pushed ${updates.length} updates for ${guid} in workspace ${workspaceId}`
);
resolve();
resolve(timestamp);
},
error: e => {
this.logger.error('Failed to push updates', e);
Expand Down

0 comments on commit a721b38

Please sign in to comment.