diff --git a/R/session.R b/R/session.R index 26f2943..ff7f53a 100644 --- a/R/session.R +++ b/R/session.R @@ -20,6 +20,13 @@ cog_open <- function(url = .resolve_url(), # a remote read should already be bound by whatever budget the operator set. .apply_duckdb_limits(con, threads, memory_limit) DBI::dbExecute(con, "INSTALL httpfs; LOAD httpfs;") + # Remote path: without this, every CREATE VIEW in .register_views() and + # every query re-requests the same file metadata over HTTP -- about 4 s of + # a 5.6 s session open against the public corpus (#64). The cache lives as + # long as the connection; cog_close() discards it. A corpus republished + # mid-session is not picked up until then, which matches the manifest, + # already fixed for the session. + DBI::dbExecute(con, "SET enable_http_metadata_cache = true") manifest <- .fetch_or_cache_manifest(url, cache_dir) .validate_schema(manifest, supported = c(4L, 5L, 6L, 7L)) diff --git a/tests/testthat/test-http-metadata-cache.R b/tests/testthat/test-http-metadata-cache.R new file mode 100644 index 0000000..cd0f702 --- /dev/null +++ b/tests/testthat/test-http-metadata-cache.R @@ -0,0 +1,23 @@ +# tests/testthat/test-http-metadata-cache.R +# +# uscogdata#64. On the remote path every CREATE VIEW re-requested the same +# file metadata over HTTP: 23 views at about 0.35 s each made session open +# take about 6 s against the public corpus. DuckDB's HTTP metadata cache keeps +# those responses for the life of the connection. Measured on 2026-11-12 +# against the Hugging Face corpus, one run per arm: session open 5.6 s -> +# 1.6 s, first one-year query 1.2 s -> 0.8 s, the same query again +# 0.55 s -> 0.02 s. +# +# The fixture is local, so these tests can only check that the setting is on, +# not that it saves anything. + +test_that("cog_open() turns on DuckDB's HTTP metadata cache (#64)", { + skip_if_no_corpus() + uscogdata:::cog_close() + on.exit(uscogdata:::cog_close(), add = TRUE) + con <- uscogdata:::cog_open() + v <- DBI::dbGetQuery( + con, "SELECT current_setting('enable_http_metadata_cache') AS v" + )$v[[1]] + expect_true(isTRUE(as.logical(v))) +})