Repository: toeverything/AFFiNE
File: packages/backend/server/src/core/doc/reader.ts (TypeScript)

Code before:
      ...this.docDiff(doc.bin, stateVector),
      timestamp: doc.timestamp,
    };
  }

  protected override async getDocContentWithoutCache(
    workspaceId: string,
    guid: string
  ): Promise<PageDocContent | null> {
    const docRecord = await this.workspace.getDoc(workspaceId, guid);
    if (!docRecord) {
      return null;
    }
    return this.parseDocContent(docRecord.bin);
  }

  protected override async getWorkspaceContentWithoutCache(
    workspaceId: string
  ): Promise<WorkspaceDocInfo | null> {
    const docRecord = await this.workspace.getDoc(workspaceId, workspaceId);
    if (!docRecord) {
      return null;
    }
    const content = this.parseWorkspaceContent(docRecord.bin);
    if (!content) {
      return null;
    }
    let avatarUrl: string | undefined;
    if (content.avatarKey) {
      avatarUrl = this.blobStorage.getAvatarUrl(workspaceId, content.avatarKey);
    }
    return {
      id: workspaceId,
      name: content.name,
      avatarKey: content.avatarKey,
      avatarUrl,
    };
  }
}

@Injectable()
export class RpcDocReader extends DatabaseDocReader {
  protected override readonly logger = new Logger(DocReader.name);

  constructor(
    private readonly config: Config,
    private readonly crypto: CryptoHelper,
    protected override readonly cache: Cache,
    protected override readonly models: Models,
    protected override readonly blobStorage: WorkspaceBlobStorage,
    protected override readonly workspace: PgWorkspaceDocStorageAdapter

Review comment (performance):
<!--__GRAPHITE_HTML_TAG_START__--><p class='graphite__hidden'><i>[Re: line +348]</i></p><!--__GRAPHITE_HTML_TAG_END__-->
I suddenly remembered that I still need to implement getDocContentWithoutCache in RpcDocReader
<!--__GRAPHITE_HTML_TAG_START__--><p class='graphite__hidden'>See this comment inline on <a href="https://app.graphite.dev/github/pr/toeverything/AFFiNE/11138?utm_source=unchanged-line-comment">Graphite</a>.</p><!--__GRAPHITE_HTML_TAG_END__-->

Code after:
    docId: string,
    stateVector?: Uint8Array
  ): Promise<DocDiff | null> {
    const doc = await this.workspace.getDoc(spaceId, docId);
    if (!doc) {
      return null;
    }
    return {
      ...this.docDiff(doc.bin, stateVector),
      timestamp: doc.timestamp,
    };
  }

  protected override async getDocContentWithoutCache(
    workspaceId: string,
    guid: string,
    fullContent?: boolean
  ): Promise<PageDocContent | null> {
    const docRecord = await this.workspace.getDoc(workspaceId, guid);
    if (!docRecord) {
      return null;
    }
    return this.parseDocContent(docRecord.bin, fullContent ? -1 : 150);
  }

  protected override async getWorkspaceContentWithoutCache(
    workspaceId: string
  ): Promise<WorkspaceDocInfo | null> {
    const docRecord = await this.workspace.getDoc(workspaceId, workspaceId);
    if (!docRecord) {
      return null;
    }
    const content = this.parseWorkspaceContent(docRecord.bin);
    if (!content) {
      return null;
    }
    let avatarUrl: string | undefined;
    if (content.avatarKey) {
      avatarUrl = this.blobStorage.getAvatarUrl(workspaceId, content.avatarKey);
    }
    return {
      id: workspaceId,
      name: content.name,
      avatarKey: content.avatarKey,
      avatarUrl,
    };
  }
}

@Injectable()
export class RpcDocReader extends DatabaseDocReader {