62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/e621/csv_importable.rb', line 62
def import_from_csv(csv_path, truncate: false, recreate_indexes: false, chunk_bytes: 1 << 20)
model = T.unsafe(self)
indexes = recreate_indexes ? secondary_index_definitions : {}
if truncate
ActiveSupport::Notifications.instrument("truncate.e621_export_downloader", table: model.table_name) do
model.connection.execute("TRUNCATE #{model.quoted_table_name}")
end
end
indexes.each_key do |name|
ActiveSupport::Notifications.instrument("drop_index.e621_export_downloader", table: model.table_name, index: name) do
model.connection.execute("DROP INDEX IF EXISTS #{name}")
end
end
count = begin
ActiveSupport::Notifications.instrument("copy.e621_export_downloader", table: model.table_name) do |payload|
copy_csv(csv_path, chunk_bytes: chunk_bytes).tap { |rows| payload[:rows] = rows }
end
ensure
indexes.each do |name, ddl|
ActiveSupport::Notifications.instrument("create_index.e621_export_downloader", table: model.table_name, index: name) do
model.connection.execute(ddl)
end
end
end
self.row_count = count
count
end
|