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

Finally rip out these Connect user and content caches #793

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

* Changed the function signature of `pin_write()` so arguments like `type` and `title` must be passed by name and not position (#792).

## Other improvements

* Removed content and user caches for Connect altogether. Now, we look up
usernames and content on the Connect server every time (#793).

# pins 1.2.2

* Fixed how dots are checked in `pin_write()` to make user-facing messages more
Expand Down
31 changes: 3 additions & 28 deletions R/board_connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,8 @@
#' ))
#' board %>% pin_read("numbers")
#' ```
#'
#' You can find the URL of a pin with [pin_browse()].
#'
#' # Local caching for Posit Connect
#'
#' The pins package maintains local per-session caches for _users_ and _content_
#' from your Connect server. If your cache gets into a bad state (for example,
#' user names have changed on the server or a pin was deleted on the server, but
#' your local machine doesn't know about the change yet), you can clear your
#' local cache by restarting your R session.
#' You can find the URL of a pin with [pin_browse()].
#'
#' @inheritParams new_board
#' @inheritParams board_url
Expand Down Expand Up @@ -437,21 +429,9 @@ board_pin_find.pins_board_connect <- function(board,

# Content -----------------------------------------------------------------

the <- rlang::new_environment()
the$connect_content_cache <- rlang::new_environment()
the$connect_user_cache <- rlang::new_environment()

rsc_content_find <- function(board, name, version = NULL, warn = TRUE) {
name <- rsc_parse_name(name)
content <- rlang::env_cache(
env = the$connect_content_cache,
nm = name$full %||% name$name,
default = rsc_content_find_live(board, name, version = NULL, warn = TRUE)
)
content
}

rsc_content_find_live <- function(board, name, version = NULL, warn = TRUE) {
name <- rsc_parse_name(name)

# https://docs.rstudio.com/connect/api/#get-/v1/content
json <- rsc_GET(board, "v1/content", list(name = name$name))
Expand Down Expand Up @@ -573,7 +553,6 @@ rsc_content_version_cached <- function(board, guid) {
rsc_content_delete <- function(board, name) {
content <- rsc_content_find(board, name)
rsc_DELETE(board, rsc_v1("content", content$guid))
env_unbind(the$connect_content_cache, name)
invisible(NULL)
}

Expand All @@ -588,11 +567,7 @@ rsc_parse_name <- function(x) {
}

rsc_user_name <- function(board, guid) {
rlang::env_cache(
env = the$connect_user_cache,
nm = guid,
rsc_GET(board, rsc_v1("users", guid))$username
)
rsc_GET(board, rsc_v1("users", guid))$username
}

# helpers -----------------------------------------------------------------
Expand Down
8 changes: 0 additions & 8 deletions man/board_connect.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/board_connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Code
rsc_content_find(board, "marjory/test-partial")
Condition
Error in `rsc_content_find_live()`:
Error in `rsc_content_find()`:
! Can't find pin named 'test-partial' with owner 'marjory'

# can create and delete content
Expand All @@ -47,7 +47,7 @@
Code
rsc_content_delete(board, "test-1")
Condition
Error in `rsc_content_find_live()`:
Error in `rsc_content_find()`:
! Can't find pin called "test-1"
i Use `pin_list()` to see all available pins in this board

Loading