Skip to content

Performance: Optimize sequential OEmbed fetching in rocketUrlParser to run concurrently #39710

@himanshu2006

Description

@himanshu2006

Currently, the rocketUrlParser in the AfterSaveOEmbed hook processes message URLs sequentially using a for await...of loop. When a user sends a single message containing multiple external URLs, the server halts and waits for each parseUrl() HTTP request to completely resolve before initiating the next one.This creates an $O(N)$ network latency bottleneck. If a message contains 4 URLs, and each takes 1.5 seconds to respond, the thread is blocked for 6 seconds. Refactoring this to fetch the metadata concurrently (e.g., using Promise.all or Promise.allSettled) will reduce the total processing time to the duration of the single slowest request.

Steps to reproduce:

  1. Boot up a local Rocket.Chat development server.
  2. Ensure OEmbed/Link Previews are enabled in Administration -> Settings -> Message.
  3. Send a single message in any channel containing 4 or 5 different external URLs (e.g., various news articles or YouTube links).
  4. Trace the server execution logs or observe the response time. The URLs are fetched one after the other, causing a noticeable delay in processing the final message state.

Expected behavior:
The server should initiate the OEmbed HTTP requests for all valid URLs in the message array concurrently, drastically reducing the total time spent in the rocketUrlParser hook.

Actual behavior:
The server waits for parseUrl(item.url) to completely finish before starting the network request for the next URL in the array, creating a sequential blocking queue.

Server Setup Information:

  1. Version of Rocket.Chat Server: develop branch (Latest)
  2. License Type: Community
  3. Number of Users: Local Dev (1)
  4. Operating System: Linux/WSL
  5. Deployment Method: Local Development
  6. Number of Running Instances: 1
  7. DB Replicaset Oplog: Enabled
  8. NodeJS Version: 22.16.0
  9. MongoDB Version: 8.2.4

Client Setup Information
Desktop App or Browser Version: Chrome/Brave (Latest)
Operating System: Windows / Linux

Additional context
Target File: apps/meteor/app/lib/server/functions/hooks/AfterSaveOEmbed.ts
Target Function: rocketUrlParserI

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: featurePull requests that introduces new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions