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

Separate data retrieval from updated date filtering #952

Merged
merged 1 commit into from
Jul 4, 2023
Merged
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
16 changes: 13 additions & 3 deletions lib/traject/readers/folio_postgres_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@ def each

# declare a cursor
queries = if @updated_after
conditions = %w[vi hr item cr cl cc].map { |table| "sul_mod_inventory_storage.strtotimestamp((#{table}.jsonb -> 'metadata'::text) ->> 'updatedDate'::text) > '#{@updated_after}'" }.map { |q| [q, @sql_filters].compact }
conditions.map { |c| sql_query(c) }.join(') UNION (')
filter_join = {
'hr_filter' => 'LEFT JOIN sul_mod_inventory_storage.holdings_record hr_filter ON hr_filter.instanceid = vi.id',
'item_filter' => 'LEFT JOIN sul_mod_inventory_storage.item item_filter ON item_filter.holdingsrecordid = hr.id',
'cr_filter' => 'LEFT JOIN sul_mod_courses.coursereserves_reserves cr_filter ON (cr_filter.jsonb ->> \'itemId\')::uuid = item.id',
'cl_filter' => 'LEFT JOIN sul_mod_courses.coursereserves_courselistings cl_filter ON cl_filter.id = cr.courselistingid',
'cc_filter' => 'LEFT JOIN sul_mod_courses.coursereserves_courses cc_filter ON cc_filter.courselistingid = cl.id'
}
conditions = %w[vi hr_filter item_filter cr_filter cl_filter cc_filter].map do |table|
"sul_mod_inventory_storage.strtotimestamp((#{table}.jsonb -> 'metadata'::text) ->> 'updatedDate'::text) > '#{@updated_after}'"
end
conditions.map { |c| sql_query([c, @sql_filters].compact, addl_from: filter_join[c]) }.join(') UNION (')
else
sql_query([@sql_filters])
end
Expand All @@ -60,7 +69,7 @@ def last_response_date
Time.parse(@connection.exec('SELECT NOW()').getvalue(0, 0))
end

def sql_query(conditions)
def sql_query(conditions, addl_from: nil)
<<-SQL
WITH viewLocations(locId, locJsonb, locCampJsonb, locLibJsonb, locInstJsonb) AS (
SELECT loc.id AS locId,
Expand Down Expand Up @@ -288,6 +297,7 @@ def sql_query(conditions)
-- BW Parent Item's Temporary location relation
LEFT JOIN viewLocations parentItemTempLoc
ON (parentItem.jsonb ->> 'temporaryLocationId')::uuid = parentItemTempLoc.locId
#{addl_from}
WHERE #{conditions.join(' AND ')}
GROUP BY vi.id
SQL
Expand Down