Skip to content
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

[WAIT] When processing a route, use most specific mount paths first #748

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

schloerke
Copy link
Collaborator

@schloerke schloerke commented Dec 31, 2020

Fixes #734
Fixes #773

  • More specific mount paths will be found by using this order

Reprex:

pr <- pr() %>% 
  pr_mount("/aaa", pr()) %>%
  pr_mount("/aaa/bbb",
           pr() %>% 
             pr_get("/hello", function() "hi")
  ) %>% pr_run()

... Which mount processes /aaa/bbb/hello?

  • Before pr: /aaa
  • With pr: /aaa/bbb

PR task list:

  • Update NEWS
  • Add tests
  • Update documentation with devtools::document()

Questions:

  • Is it ok to return different order for pr$mounts?
    • Now it is alpha sorted. Before, it was the order in which they were added.
    • I think this new order is reasonable as it reflects the processing order.

Answer: No. Keep pr$mounts the same

@schloerke schloerke added this to the v1.1.0 milestone Dec 31, 2020
@schloerke schloerke marked this pull request as ready for review December 31, 2020 19:13
private$mnts
mnts <- private$mnts
if (length(mnts) == 0) return(mnts)
mnts[sort(names(mnts), decreasing = FALSE)]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
mnts[sort(names(mnts), decreasing = FALSE)]
mnts[order(names(mnts), decreasing = FALSE)]

# * Mounts `/aaa` and `/aaa/bbb` exist.
# * We want to use mount `/aaa/bbb` as it is more specific
# TODO
# * If `/aaa/bbb` mount does not support `/aaa/bbb/foo`, then try mount `/aaa`.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
# * If `/aaa/bbb` mount does not support `/aaa/bbb/foo`, then try mount `/aaa`.
# * If `/aaa/bbb` mount does not support `/aaa/bbb/foo`, then try mount `/aaa` with route `/bbb/foo`.

@@ -242,7 +248,9 @@ Plumber <- R6Class(
path <- paste0(path, "/")
}

# order the mounts so that the more specific mount paths are ahead of the less specific mount paths
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
# order the mounts so that the more specific mount paths are ahead of the less specific mount paths
# Add the mount to the original mount order
private$mnt_order <- c(private$mnt_order, path)
# Order the mounts so that the more specific mount paths are ahead of the less specific mount paths

Comment on lines +1052 to +1054
mnts <- private$mnts
if (length(mnts) == 0) return(mnts)
mnts[sort(names(mnts), decreasing = FALSE)]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
mnts <- private$mnts
if (length(mnts) == 0) return(mnts)
mnts[sort(names(mnts), decreasing = FALSE)]
private$mnts[private$mnt_order]

@schloerke schloerke marked this pull request as draft January 4, 2021 16:59
@schloerke
Copy link
Collaborator Author

This change is deemed too dangerous. Maybe approach this with pr_merge() (##749) instead?

cc @cpsievert

@schloerke schloerke modified the milestones: v1.1.0, v1.2.0 Jan 5, 2021
@schloerke schloerke changed the title When processing a route, use most specific mount paths first [WAIT] When processing a route, use most specific mount paths first Jun 2, 2022
@schloerke schloerke added the theme: pr_merge() Could be resolved with pr_merge() label Jun 3, 2022
@schloerke schloerke removed this from the v1.2.0 milestone Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: pr_merge() Could be resolved with pr_merge()
Projects
None yet
1 participant