Skip to content

Commit

Permalink
Merge pull request #277 from hathitrust/DEV-550-bugfix
Browse files Browse the repository at this point in the history
Dev-550: (bugfix) Making sure variable is used properly in query
  • Loading branch information
mwarin authored Jun 6, 2023
2 parents e1261a5 + 563faef commit 38a252b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/reports/shared_print_newly_ingested.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,24 @@ def matching_item_ids_from_db
return enum_for(:matching_item_ids_from_db) unless block_given?
db = Services.holdings_db
db.run("USE ht")
query = %w[
db.fetch(query, @start_date) do |row|
yield row[:ht_id], row[:min_time]
end
end

# The query string, if going via matching_item_ids_from_db
def query
<<~HEREDOC
SELECT
CONCAT(namespace, '.', id) AS ht_id,
CONCAT(namespace, '.', id) AS ht_id,
MIN(DATE_FORMAT(time, "%Y-%m-%d")) AS min_time
FROM
rights_log
GROUP BY
namespace, id
HAVING
MIN(time) >= '#{@start_date}'
].join(" ")
db.fetch(query) do |row|
yield row[:ht_id], row[:min_time]
end
min_time >= ?
HEREDOC
end

# For testing or caching purposes, read matching items from file rather than db.
Expand Down

0 comments on commit 38a252b

Please sign in to comment.