Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBERF-7474: Some logging and reduce calls for query refresh #5973

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/query/src/__tests__/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe('query', () => {
it('remove with limit', async () => {
const { liveQuery, factory } = await getClient()

const expectedLength = 2
const expectedLength = 1
let attempt = 0
const pp = new Promise((resolve) => {
liveQuery.query<Space>(
Expand Down
32 changes: 13 additions & 19 deletions packages/query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.
//

import { Analytics } from '@hcengineering/analytics'
import core, {
AttachedDoc,
BulkUpdateEvent,
Expand Down Expand Up @@ -53,12 +54,12 @@ import core, {
generateId,
getObjectValue,
matchQuery,
reduceCalls,
resultSort,
toFindResult
} from '@hcengineering/core'
import { PlatformError } from '@hcengineering/platform'
import { deepEqual } from 'fast-equals'
import { Analytics } from '@hcengineering/analytics'

const CACHE_SIZE = 100

Expand All @@ -75,7 +76,7 @@ interface Query {
total: number
callbacks: Map<string, Callback>

requested?: Promise<void>
refresh: () => Promise<void>
}

interface DocumentRef {
Expand Down Expand Up @@ -392,7 +393,8 @@ export class LiveQuery implements WithTx, Client {
result,
total: 0,
options: options as FindOptions<Doc>,
callbacks: new Map()
callbacks: new Map(),
refresh: reduceCalls(() => this.doRefresh(q))
}
q.callbacks.set(callback.callbackId, callback.callback as unknown as Callback)
queries.push(q)
Expand Down Expand Up @@ -836,18 +838,8 @@ export class LiveQuery implements WithTx, Client {
return this.getHierarchy().clone(results) as T[]
}

private async refresh (q: Query, reRequest: boolean = false): Promise<void> {
if (q.requested !== undefined && !reRequest) {
// we already asked for refresh, just wait.
await q.requested
return
}
if (reRequest && q.requested !== undefined) {
await q.requested
}
q.requested = this.doRefresh(q)
await q.requested
q.requested = undefined
private async refresh (q: Query): Promise<void> {
await q.refresh()
}

private async doRefresh (q: Query): Promise<void> {
Expand Down Expand Up @@ -1279,6 +1271,8 @@ export class LiveQuery implements WithTx, Client {
const docCache = new Map<string, Doc>()
for (const tx of txes) {
if (tx._class === core.class.TxWorkspaceEvent) {
const evt = tx as TxWorkspaceEvent
console.info('checking workspace event', evt._id, evt.params)
await this.checkUpdateEvents(tx as TxWorkspaceEvent)
await this.changePrivateHandler(tx as TxWorkspaceEvent)
}
Expand All @@ -1304,7 +1298,7 @@ export class LiveQuery implements WithTx, Client {
if (hasClass(q, indexingParam._class) && q.query.$search !== undefined) {
if (!this.removeFromQueue(q)) {
try {
await this.refresh(q, true)
await this.refresh(q)
} catch (err: any) {
Analytics.handleError(err)
console.error(err)
Expand All @@ -1325,7 +1319,7 @@ export class LiveQuery implements WithTx, Client {
for (const q of v) {
if (hasClass(q, indexingParam._class) && q.query.$search !== undefined) {
try {
await this.refresh(q, true)
await this.refresh(q)
} catch (err: any) {
Analytics.handleError(err)
console.error(err)
Expand All @@ -1340,7 +1334,7 @@ export class LiveQuery implements WithTx, Client {
if (hasClass(q, params._class)) {
if (!this.removeFromQueue(q)) {
try {
await this.refresh(q, true)
await this.refresh(q)
} catch (err: any) {
Analytics.handleError(err)
console.error(err)
Expand All @@ -1352,7 +1346,7 @@ export class LiveQuery implements WithTx, Client {
for (const q of v) {
if (hasClass(q, params._class)) {
try {
await this.refresh(q, true)
await this.refresh(q)
} catch (err: any) {
Analytics.handleError(err)
console.error(err)
Expand Down
1 change: 1 addition & 0 deletions server/core/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export async function createServerStorage (
metrics.newChild('fulltext', {}),
modelDb,
(classes: Ref<Class<Doc>>[]) => {
ctx.info('broadcast indexing update', { classes, workspace: conf.workspace })
const evt: IndexingUpdateEvent = {
_class: classes
}
Expand Down