mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 10:45:57 +08:00
refactor(server): remove unused randomDoc method (#10985)
close CLOUD-177
This commit is contained in:
@@ -2,7 +2,6 @@ import { Injectable, Logger } from '@nestjs/common';
|
|||||||
import { chunk } from 'lodash-es';
|
import { chunk } from 'lodash-es';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Cache,
|
|
||||||
DocHistoryNotFound,
|
DocHistoryNotFound,
|
||||||
DocNotFound,
|
DocNotFound,
|
||||||
EventBus,
|
EventBus,
|
||||||
@@ -22,7 +21,6 @@ import {
|
|||||||
HistoryFilter,
|
HistoryFilter,
|
||||||
} from '../storage';
|
} from '../storage';
|
||||||
|
|
||||||
const UPDATES_QUEUE_CACHE_KEY = 'doc:manager:updates';
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Events {
|
interface Events {
|
||||||
'doc.snapshot.deleted': {
|
'doc.snapshot.deleted': {
|
||||||
@@ -50,7 +48,6 @@ export class PgWorkspaceDocStorageAdapter extends DocStorageAdapter {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly models: Models,
|
private readonly models: Models,
|
||||||
private readonly mutex: Mutex,
|
private readonly mutex: Mutex,
|
||||||
private readonly cache: Cache,
|
|
||||||
private readonly event: EventBus,
|
private readonly event: EventBus,
|
||||||
protected override readonly options: DocStorageOptions,
|
protected override readonly options: DocStorageOptions,
|
||||||
private readonly queue: JobQueue
|
private readonly queue: JobQueue
|
||||||
@@ -377,35 +374,4 @@ export class PgWorkspaceDocStorageAdapter extends DocStorageAdapter {
|
|||||||
protected async lastDocHistory(workspaceId: string, id: string) {
|
protected async lastDocHistory(workspaceId: string, id: string) {
|
||||||
return this.models.history.getLatest(workspaceId, id);
|
return this.models.history.getLatest(workspaceId, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// for auto merging
|
|
||||||
async randomDoc() {
|
|
||||||
const key = await this.cache.mapRandomKey(UPDATES_QUEUE_CACHE_KEY);
|
|
||||||
|
|
||||||
if (key) {
|
|
||||||
const cachedCount = await this.cache.mapIncrease(
|
|
||||||
UPDATES_QUEUE_CACHE_KEY,
|
|
||||||
key,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
if (cachedCount > 0) {
|
|
||||||
const [workspaceId, id] = key.split('::');
|
|
||||||
const count = await this.models.doc.getUpdateCount(workspaceId, id);
|
|
||||||
|
|
||||||
// FIXME(@forehalo): somehow the update count in cache is not accurate
|
|
||||||
if (count === 0) {
|
|
||||||
metrics.doc
|
|
||||||
.counter('doc_update_count_inconsistent_with_cache')
|
|
||||||
.add(1);
|
|
||||||
await this.cache.mapDelete(UPDATES_QUEUE_CACHE_KEY, key);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return { workspaceId, docId: id };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user