Skip to content

Commit

Permalink
Tableau Export: stream CSV from database
Browse files Browse the repository at this point in the history
Will provide the data necessary for tableau viz much faster than the GBL Admin CSV export.
  • Loading branch information
ewlarson committed Dec 6, 2023
1 parent 48cddbe commit 2f5e6ac
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
42 changes: 42 additions & 0 deletions app/controllers/admin/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,48 @@ class ApiController < ApplicationController
config.autocomplete_path = 'suggest'
end

# Admin CSV stream of Database data
def tableau_export
headers.delete("Content-Length")
headers["Cache-Control"] = "no-cache"
headers["Content-Type"] = "text/csv"
headers["Content-Disposition"] = "attachment; filename=\"geoportal_tableau_export.csv\""
headers["X-Accel-Buffering"] = "no"
response.status = 200
self.response_body = csv_enumerator
end

def csv_enumerator
@csv_enumerator ||= Enumerator.new do |yielder|
yielder << CSV.generate_line([
"Title",
"Provider",
"Resource Class",
"Resource Type",
"Index Year",
"Spatial Coverage",
"B1G Image",
"ID",
"Download",
"Language"
])
Document.find_each do |row|
yielder << CSV.generate_line([
row.title,
row.schema_provider_s,
row.gbl_resourceClass_sm&.join("|"),
row.gbl_resourceType_sm&.join("|"),
row.gbl_indexYear_im&.join("|"),
row.dct_spatial_sm&.join("|"),
row.b1g_image_ss,
row.geomg_id_s,
row.dct_references_s.find { |ref| ref.category == "download" }&.value,
row.dct_language_sm&.join("|")
])
end
end
end

# Administrative view of document
# - Sidecar Image
# - URIs
Expand Down
1 change: 1 addition & 0 deletions app/views/robots/robots.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Disallow: /?f
Disallow: /?_
Disallow: /?bbox
Disallow: /?page=
Disallow: /admin/api/tableau_export
Disallow: /catalog.html?f
Disallow: /catalog.html?_
Disallow: /catalog.atom
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
get '/api' => 'api#index', constraints: lambda { |req| req.format == :json }
get '/api/fetch' => 'api#fetch', constraints: lambda { |req| req.format == :json }
get '/api/facet/:id' => 'api#facet', constraints: lambda { |req| req.format == :json }
get '/api/tableau_export' => 'api#tableau_export'

# Documents
resources :documents do
Expand Down

0 comments on commit 2f5e6ac

Please sign in to comment.