Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 8, 2025

The @id field contains full URLs (e.g., http://localhost:3005/v1/id/abc123) and is not indexed. The _id field contains the hexstring (abc123) and is indexed by MongoDB. Queries were using @id for lookups, causing full collection scans.

Changes

Query optimization in getAllVersions()

  • Extract hexstring from @id URL using parseDocumentID()
  • Query by indexed _id field instead of @id
  • Maintains slug support via $or query
// Before: O(n) collection scan
await db.findOne({ "@id": primeID })

// After: O(log n) indexed lookup
const primeHexId = parseDocumentID(primeID)
await db.findOne({"$or":[{"_id": primeHexId}, {"__rerum.slug": primeHexId}]})

Code consolidation

  • Removed duplicate getAllVersions() and getAllDescendants() from controllers/delete.js
  • Import from controllers/utils.js instead

Error handling

  • Validate primeID exists before parsing
  • Check query result before dereferencing
  • Wrap parseDocumentID() with contextual error messages

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • iojs.org
    • Triggering command: /usr/bin/curl curl --fail --compressed -q -L -s REDACTED -o - (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Use _id when possible</issue_title>
<issue_description>There are several ways to see a document. The _id property is always a hexstring and it used in the @id or id field as the suffix after the last "/". Since _id is indexed, any queries or find requests that are looking at "@id" or "id" should be altered to just match the _id hexstring instead.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 8, 2025 21:42
Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
@cubap cubap marked this pull request as ready for review December 8, 2025 21:49
@cubap cubap requested review from cubap and thehabes as code owners December 8, 2025 21:49
@cubap
Copy link
Member

cubap commented Dec 8, 2025

We already had a parseDocumentID() in there. We knew this was coming.

Copilot AI and others added 2 commits December 8, 2025 21:50
Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
Copilot AI changed the title [WIP] Update queries to use _id property Use indexed _id field instead of @id for database queries Dec 8, 2025
Copy link
Member

@thehabes thehabes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually tested and test with AI for errors, and to see if we could still cause undefined for different @id/id patterns. I don't think that old error is applicable anymore.

I also checked for other places where we may want to make this change to do _id look ups but there were not anymore, this should do it.

@thehabes thehabes merged commit ba70798 into main Dec 9, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use _id when possible

3 participants