-
Notifications
You must be signed in to change notification settings - Fork 13.1k
chore: remove left over oplog code #38313
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
Open
sampaiodiego
wants to merge
3
commits into
develop
Choose a base branch
from
remove-oplog-stuff
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { MongoInternals } from 'meteor/mongo'; | ||
|
|
||
| type Callbacks = { | ||
| added(id: string, record: object): void; | ||
| changed(id: string, record: object): void; | ||
| removed(id: string): void; | ||
| }; | ||
|
|
||
| export const serviceConfigCallbacks = new Set<Callbacks>(); | ||
|
|
||
| // Stores the callbacks for the disconnection reactivity bellow | ||
| const userCallbacks = new Map(); | ||
|
|
||
| // Overrides the native observe changes to prevent database polling and stores the callbacks | ||
| // for the users' tokens to re-implement the reactivity based on our database listeners | ||
| const { mongo } = MongoInternals.defaultRemoteCollectionDriver(); | ||
| MongoInternals.Connection.prototype._observeChanges = async function ( | ||
| { | ||
| collectionName, | ||
| selector, | ||
| options = {}, | ||
| }: { | ||
| collectionName: string; | ||
| selector: Record<string, any>; | ||
| options?: { | ||
| projection?: Record<string, number>; | ||
| fields?: Record<string, number>; | ||
| }; | ||
| }, | ||
| _ordered: boolean, | ||
| callbacks: Callbacks, | ||
| ): Promise<any> { | ||
| let cbs: Set<{ hashedToken: string; callbacks: Callbacks }>; | ||
| let data: { hashedToken: string; callbacks: Callbacks }; | ||
| if (callbacks?.added) { | ||
| const records = await mongo | ||
| .rawCollection(collectionName) | ||
| .find(selector, { | ||
| ...(options.projection || options.fields ? { projection: options.projection || options.fields } : {}), | ||
| }) | ||
| .toArray(); | ||
|
|
||
| for (const { _id, ...fields } of records) { | ||
| callbacks.added(String(_id), fields); | ||
| } | ||
|
|
||
| if (collectionName === 'users' && selector['services.resume.loginTokens.hashedToken']) { | ||
| cbs = userCallbacks.get(selector._id) || new Set(); | ||
| data = { | ||
| hashedToken: selector['services.resume.loginTokens.hashedToken'], | ||
| callbacks, | ||
| }; | ||
|
|
||
| cbs.add(data); | ||
| userCallbacks.set(selector._id, cbs); | ||
| } | ||
| } | ||
|
|
||
| if (collectionName === 'meteor_accounts_loginServiceConfiguration') { | ||
| serviceConfigCallbacks.add(callbacks); | ||
| } | ||
|
|
||
| return { | ||
| stop(): void { | ||
| if (cbs) { | ||
| cbs.delete(data); | ||
| } | ||
| serviceConfigCallbacks.delete(callbacks); | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| // Re-implement meteor's reactivity that uses observe to disconnect sessions when the token | ||
| // associated was removed | ||
| export const processOnChange = (diff: Record<string, any>, id: string): void => { | ||
| if (!diff || !('services.resume.loginTokens' in diff)) { | ||
| return; | ||
| } | ||
| const loginTokens: undefined | { hashedToken: string }[] = diff['services.resume.loginTokens']; | ||
| const tokens = loginTokens?.map(({ hashedToken }) => hashedToken); | ||
|
|
||
| const cbs = userCallbacks.get(id); | ||
| if (cbs) { | ||
| [...cbs] | ||
| .filter(({ hashedToken }) => tokens === undefined || !tokens.includes(hashedToken)) | ||
| .forEach((item) => { | ||
| item.callbacks.removed(id); | ||
| cbs.delete(item); | ||
| }); | ||
| } | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 1553
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 2804
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 48
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 121
🏁 Script executed:
#!/bin/bash cat -n apps/meteor/server/services/meteor/userReactivity.tsRepository: RocketChat/Rocket.Chat
Length of output: 3434
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 48
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 527
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 793
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 30556
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 9011
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 3795
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 84
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 5969
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 960
🏁 Script executed:
Repository: RocketChat/Rocket.Chat
Length of output: 524
The
_observeChangesoverride needs to return a synchronous handle withisReadyandisReadyPromiseproperties.This async override may break the Meteor contract. The original
_observeChangesshould return a synchronous handle immediately (not a Promise), with the initial query run asynchronously. The returned handle must includeisReady(boolean) andisReadyPromise(Promise) properties—currently onlystop()is provided. Additionally, the options parameter only forwardsprojection/fieldsbut omitssort,limit, and other common query options, which could cause unexpected query behavior.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is completely wrong, where did you get this info from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
@sampaiodiegoI apologize for the incorrect analysis. Let me search for the actual Meteor documentation to understand the correct contract for_observeChanges.🌐 Web query:
💡 Result:
MongoInternals.Connection#_observeChangesis Meteor’s server-side internal hook that powersMongo.Cursor#observeChanges(...)/observeChangesAsync(...). While it’s not a public API, the “contract” it must satisfy is effectively the same as the publicobserveChanges*semantics:Inputs (conceptually)
sort/limit/skip/fields, etc.).added/changed/removed.addedBefore/movedBefore(and may still usechanged/removed).Callback contract
Meteor will call (some subset of) these callbacks, with these meanings:
added(id, fields)oraddedBefore(id, fields, before)fieldsis the full document minus_id.beforeis the_idof the doc that follows it in sort order, ornullfor “at end”.changed(id, fields)fieldscontains only changed keys; removed keys appear with valueundefined.removed(id)movedBefore(id, before)(ordered observers only)beforeis the following doc’s id, ornullfor “at end”.These definitions are documented for
observeChangesAsync, and apply equivalently to the underlying implementation. [1]Timing / lifecycle contract
added/addedBeforezero-or-more times to publish the initial result set, then returns the handle. [1]_observeChangesreturns a live query handle with at least:stop()— stops observation and releases resources. [1]Ordering rule (practical requirement)
If the query uses
skip/limit(and generally any ordering-sensitive query), Meteor expects an ordered observe (callbacks likeaddedBeforeinstead ofadded), otherwise you’ll hit errors like: “must use ordered observe … with skip or limit”. [2]If you share what you’re implementing (e.g., a custom observe driver / alternative Mongo driver), I can map the exact callback set you must support for your specific query shapes (ordered vs unordered) and how to translate DB events into these callbacks.
Sources:
[1] https://docs.meteor.com/api/collections (section:
Cursor.observeChangesAsynccallbacks + initial-add-before-return + handle.stop)[2] https://stackoverflow.com/questions/36099080/server-function-call-on-document-observe-changes (ordered observe requirement/error)
@sampaiodiegoI apologize for the incorrect review comment. Based on the Meteor documentation I found, I can see that I was wrong about theisReadyandisReadyPromiseproperties being required—the standard contract only requires astop()method on the returned handle.Could you help me understand what was incorrect about my analysis? I want to learn from this mistake so I can provide better reviews in the future. Specifically:
Thank you for your patience in correcting me.
🧠 Learnings used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know where you get the definitions for
_observeChangesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 1156
🏁 Script executed:
Length of output: 2947
🌐 Web query:
💡 Result:
In Meteor core,
MongoInternals.Connection.prototype._observeChangeslives in the server-sidemongopackage and is implemented (as of the Meteor 3.3.x line) in:packages/mongo/mongo_connection.js(the connection class) (fossies.org)packages/mongo/observe_multiplex.ts(the “observe multiplexer” that deduplicates identical live queries) (fossies.org)How
_observeChangesis structured (high level)ObserveMultiplexerkeyed by that cursor description, so multiple callers observing the same query share one underlying driver and fan out callbacks.ObserveMultiplexerchooses an observe driver:OplogObserveDriver(oplog tailing) when the query is supported.PollingObserveDriverwhen it’s not. (fossies.org)addedcallbacks) and then streams changes via oplog tailing or polling/diff.The underlying drivers you’ll end up reading
packages/mongo/oplog_observe_driver.js(exportsOplogObserveDriver) (fossies.org)packages/mongo/polling_observe_driver.ts(fossies.org)docs/long-form/oplog-observe-driver.md(fossies.org)If you tell me which Meteor version/branch you’re targeting (e.g., Meteor
3.3.2,devel, etc.), I can point you to the exact function signature and the specific call chain inside that version’smongo_connection.js/observe_multiplex.ts.Citations:
@sampaiodiegoI apologize for the confusion. I was making inferences based on:observeChanges()(the public API)I don't have access to the actual Meteor internal source code or its type definitions in this repository, so I was incorrectly assuming that the internal
_observeChangesmethod would follow the same patterns as the public API. This was a mistake on my part.Could you help me understand:
MongoInternals.Connection.prototype._observeChanges?I want to learn from this so I can provide more accurate reviews in the future, especially when it comes to internal Meteor APIs that your team is working with.
🧠 Learnings used