reports: fix error when report is empty.

Fix an exception when a report is empty, for example when performing a
tag search that returns no results:

* https://betabooru.donmai.us/reports/posts?search[group]=uploader&search[tags]=does_not_exist
This commit is contained in:
evazion
2022-10-23 21:48:48 -05:00
parent 5565c753d0
commit 0d835983ce
5 changed files with 22 additions and 4 deletions

View File

@@ -4,7 +4,7 @@
module Danbooru
class DataFrame
attr_reader :df
delegate :head, :shape, :types, :rename, :each_row, :[], :[]=, to: :df
delegate :head, :shape, :names, :types, :rename, :empty?, :each_row, :[], :[]=, to: :df
def initialize(...)
@df = Rover::DataFrame.new(...)
@@ -17,6 +17,8 @@ module Danbooru
foreign_key = association.foreign_key
name = association.name.to_s
next table if !table.names.include?(foreign_key)
ids = table[foreign_key].to_a.uniq.compact_blank
records = association.klass.where(primary_key => ids).index_by(&primary_key.to_sym)
@@ -27,6 +29,8 @@ module Danbooru
end
def crosstab(index, pivot)
return self if empty?
new_df = DataFrame.new(index => df[index].uniq)
df[pivot].uniq.to_a.each do |value|