Skip to content

Remove redundant follow('self') traversals#103

Closed
Copilot wants to merge 2 commits intodevelopfrom
copilot/remove-follow-self-usage
Closed

Remove redundant follow('self') traversals#103
Copilot wants to merge 2 commits intodevelopfrom
copilot/remove-follow-self-usage

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

Eliminate unnecessary follow('self') calls where the self link is already available or implicit. This removes an extra traversal step in the traverson HAL navigation.

Changes

Resource methods using existing self link:

  • Resource.del(), Resource.resolve(), Resource.save() - Direct traverson request from self href
  • EntryResource.resolve() - Same optimization for both conditional branches
  • TemplateResource.resolve() - Added traverson import and direct request

Root resource access (self is implicit):

  • Core.follow() - Remove redundant follow when reloading root
  • PublicAPI.resolve() and PublicAPI.getSchema() - Root request without explicit self

Cleanup:

  • Removed obsolete requestOptions check in Resource.save() (no longer applicable with fresh request builders)

Example

// Before
del(): Promise<void> {
  return del(this[environmentSymbol], this.newRequest().follow('self'));
}

// After
del(): Promise<void> {
  return del(this[environmentSymbol], traverson.from(this.getLink('self').href).jsonHal());
}

For root resources where self is implicit:

// Before
get(this[environmentSymbol], this.newRequest().follow('self'))

// After
get(this[environmentSymbol], this.newRequest())
Original prompt

remove follow('self') where possible.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: michaellocher <17722361+michaellocher@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove follow('self') where applicable Remove redundant follow('self') traversals Nov 18, 2025
Copilot AI requested a review from michaellocher November 18, 2025 17:28
@michaellocher michaellocher marked this pull request as ready for review November 18, 2025 20:10
Copilot AI review requested due to automatic review settings November 18, 2025 20:10
@michaellocher michaellocher marked this pull request as draft November 18, 2025 20:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR eliminates redundant HAL navigation steps by removing unnecessary follow('self') calls, improving code efficiency and clarity. The changes fall into two categories: using direct self link hrefs where the link is already available, and removing explicit self traversals for root resources where self is implicit.

  • Direct use of self link href via traverson.from(this.getLink('self').href).jsonHal() instead of this.newRequest().follow('self')
  • Root resource methods simplified by removing .follow('self') where the traversal already points to the root
  • Cleanup of obsolete request options handling in Resource.save()

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/resources/publicAPI/EntryResource.ts Optimized both conditional branches in resolve() to use direct self link traversal
src/resources/datamanager/TemplateResource.ts Added traverson import and updated resolve() to use direct self link traversal
src/resources/Resource.ts Updated del(), resolve(), and save() methods to use direct self link traversal; removed obsolete requestOptions cleanup
src/PublicAPI.ts Removed redundant .follow('self') from resolve() and getSchema() since root traversal is implicit
src/Core.ts Removed redundant .follow('self') from follow() method when reloading root resource

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@simon-scherzinger
Copy link
Member

The change with traverson.from(…) is not optimal.

@simon-scherzinger simon-scherzinger deleted the copilot/remove-follow-self-usage branch November 19, 2025 07:22
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.

3 participants