Skip to content

Commit

Permalink
♻️ refactor(api/createTagCollection): Leverage observeSetChanges.
Browse files Browse the repository at this point in the history
Replaces `meteor/mongo.Cursor#observeChanges`.
  • Loading branch information
make-github-pseudonymous-again committed Jul 7, 2024
1 parent 3b28f8b commit f14f5d5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions imports/api/createTagCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import type UserQuery from './query/UserQuery';
import type UserFilter from './query/UserFilter';
import type Options from './query/Options';
import type Projection from './query/Projection';
import observeSetChanges from './query/observeSetChanges';

export const STATS_SUFFIX = '.stats';
export const FIND_CACHE_SUFFIX = '.find.cache';
Expand Down Expand Up @@ -190,12 +191,12 @@ const createTagCollection = <
name: statsPublication,
authentication: AuthenticationLoggedIn,
schema: schema.tuple([schema.string()]),
handle(name) {
async handle(name) {
const uid = JSON.stringify({name, owner: this.userId});
const query = {
[key]: {$elemMatch: {name}},
owner: this.userId,
} as Selector<P>;
} as Filter<P>;
// We only include relevant fields
const options = {fields: {_id: 1, [key]: 1}};

Expand All @@ -205,7 +206,7 @@ const createTagCollection = <
// `observeChanges` only returns after the initial `added` callbacks have run.
// Until then, we don't want to send a lot of `changed` messages—hence
// tracking the `initializing` state.
const handle = Parent.find(query, options).observeChanges({
const handle = await observeSetChanges(Parent, query, options, {

Check warning on line 209 in imports/api/createTagCollection.ts

View check run for this annotation

Codecov / codecov/patch

imports/api/createTagCollection.ts#L209

Added line #L209 was not covered by tests
added: () => {
count += 1;

Expand All @@ -231,8 +232,8 @@ const createTagCollection = <
// Stop observing the cursor when the client unsubscribes. Stopping a
// subscription automatically takes care of sending the client any `removed`
// messages.
this.onStop(() => {
handle.stop();
this.onStop(async () => {
await handle.stop();
});
},
});
Expand Down

0 comments on commit f14f5d5

Please sign in to comment.