e621_export_downloader 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 570f83543711b092f8e72709bcc1c3a085ae7b865618551cf6fc4e3a9c749ec6
4
- data.tar.gz: 81af136bb9ed74d51284480bed0ae38c3dcc25865e503f19bc651ff6694ec174
3
+ metadata.gz: a133742764b3b599b2cfd4c3494391538730be19daae10e9df43956aa1913709
4
+ data.tar.gz: ec28fc8889a2ad4bef174f365985e89868068fe2f206b7325c65a3c881716942
5
5
  SHA512:
6
- metadata.gz: b149322e32f32367c823377da011d5676227e7e4e454ff09eadabca03fdad57255bb72f5c10472a40e91594ec00e3bed8a47855dbc9deb7fd303c25a2fb941c3
7
- data.tar.gz: 4edfafff035bd495ed6a9822b401853c5cc74c822cdea909403f051e8e03d55fd159d950d719023117c56fa48c9d40632e378d9dc464d554311d51992464f2c3
6
+ metadata.gz: 74262c9fc4b22df8847f75e80abb3ac9951fa7e265a306b168dcf087c64946849c2df5432d75e77a1ae8b0cc5d5869addb2348bd3b217abc7dcf02395e316521
7
+ data.tar.gz: 61dfc91a23e7c34c69562534f9a42583f362558391264d12c4761b3f2368b9633f8d0f356939efcb78a3a27d71d5a2cefbf8047d536526e02dc8d41ec2b04853
@@ -1,21 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
  # typed: true
3
3
 
4
+ require("csv")
5
+
4
6
  module E621
5
7
  module CsvImportable
6
8
  extend(T::Sig)
7
9
 
8
- sig { params(csv_path: String).returns(T.untyped) }
10
+ sig { returns(Integer) }
11
+ def row_count
12
+ E621::RowCount[T.unsafe(self).table_name.split(".").last]
13
+ end
14
+
15
+ sig { params(count: Integer).returns(T.untyped) }
16
+ def row_count=(count)
17
+ E621::RowCount.set(T.unsafe(self).table_name.split(".").last, count)
18
+ end
19
+
20
+ sig { params(csv_path: String).returns(Integer) }
9
21
  def import_from_csv(csv_path)
10
22
  model = T.unsafe(self)
11
- headers = File.open(csv_path, "rb", &:readline).chomp
12
- columns = headers.split(",").map { |h| model.connection.quote_column_name(h.strip) }.join(", ")
23
+ csv_headers = File.open(csv_path, "rb", &:readline).chomp.split(",").map(&:strip)
24
+ columns = csv_headers.map { |h| model.connection.quote_column_name(h) }.join(", ")
25
+
26
+ count = 0
13
27
  raw = model.connection.raw_connection
14
- raw.copy_data("COPY #{model.quoted_table_name} (#{columns}) FROM STDIN WITH (FORMAT CSV, HEADER TRUE)") do
15
- File.open(csv_path, "rb") do |f|
16
- raw.put_copy_data(f.read(65_536)) until f.eof?
28
+ raw.copy_data("COPY #{model.quoted_table_name} (#{columns}) FROM STDIN WITH (FORMAT CSV)") do
29
+ CSV.foreach(csv_path, headers: true) do |row|
30
+ raw.put_copy_data(CSV.generate_line(T.cast(row, CSV::Row).fields))
31
+ count += 1
17
32
  end
18
33
  end
34
+ self.row_count = count
35
+ count
19
36
  end
20
37
  end
21
38
  end
@@ -25,6 +25,7 @@ module E621
25
25
  private_class_method(def self.attributes_from_export(record)
26
26
  {
27
27
  id: record.id,
28
+ post_id: record.post_id,
28
29
  added_locked_tags: record.added_locked_tags,
29
30
  added_tags: record.added_tags,
30
31
  description: record.description,
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ require("active_record")
5
+
6
+ module E621
7
+ class RowCount < ActiveRecord::Base
8
+ extend(T::Sig)
9
+
10
+ self.table_name = "e621.row_counts"
11
+ self.primary_key = "table_name"
12
+ self.record_timestamps = false
13
+
14
+ sig { params(table_name: String).returns(Integer) }
15
+ def self.[](table_name)
16
+ find_by(table_name: table_name)&.count || 0
17
+ end
18
+
19
+ sig { params(table_name: String, count: Integer).returns(T.untyped) }
20
+ def self.set(table_name, count)
21
+ upsert({ table_name: table_name, count: count }, unique_by: :table_name)
22
+ end
23
+
24
+ sig { params(table_name: String, by: Integer).returns(T.untyped) }
25
+ def self.increment(table_name, by)
26
+ where(table_name: table_name).update_all("count = count + #{by.to_i}")
27
+ end
28
+ end
29
+ end
@@ -6,6 +6,7 @@ require_relative("../e621/pool")
6
6
  require_relative("../e621/post")
7
7
  require_relative("../e621/post_replacement")
8
8
  require_relative("../e621/post_version")
9
+ require_relative("../e621/row_count")
9
10
  require_relative("../e621/tag")
10
11
  require_relative("../e621/tag_alias")
11
12
  require_relative("../e621/tag_implication")
@@ -30,6 +30,9 @@ module E621ExportDownloader
30
30
  sig { returns(T.nilable(Integer)) }
31
31
  attr_reader(:parent_id)
32
32
 
33
+ sig { returns(Integer) }
34
+ attr_reader(:post_id)
35
+
33
36
  sig { returns(T.nilable(String)) }
34
37
  attr_reader(:rating)
35
38
 
@@ -76,6 +79,7 @@ module E621ExportDownloader
76
79
  @locked_tags = T.let(T.must(record["locked_tags"]).empty? ? nil : record["locked_tags"], T.nilable(String))
77
80
  @parent_changed = T.let(record["parent_changed"] == "t", T::Boolean)
78
81
  @parent_id = T.let(T.must(record["parent_id"]).empty? ? nil : record["parent_id"].to_i, T.nilable(Integer))
82
+ @post_id = T.let(record["post_id"].to_i, Integer)
79
83
  @rating = T.let(T.must(record["rating"]).empty? ? nil : record["rating"], T.nilable(String))
80
84
  @rating_changed = T.let(record["rating_changed"] == "t", T::Boolean)
81
85
  @reason = T.let(T.must(record["reason"]).empty? ? nil : record["reason"], T.nilable(String))
@@ -102,6 +106,7 @@ module E621ExportDownloader
102
106
  locked_tags: @locked_tags,
103
107
  parent_changed: @parent_changed,
104
108
  parent_id: @parent_id,
109
+ post_id: @post_id,
105
110
  rating: @rating,
106
111
  rating_changed: @rating_changed,
107
112
  reason: @reason,
@@ -4,7 +4,7 @@
4
4
  # loaded by bundler
5
5
  module E621ExportDownloader
6
6
  module Constants
7
- VERSION = "0.0.11"
7
+ VERSION = "0.0.13"
8
8
  WEBSITE = "https://github.com/DonovanDMC/E621ExportDownloader.rb"
9
9
  end
10
10
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  class CreateE621Tables < ActiveRecord::Migration<%= migration_version %>
4
4
  def change
5
+ enable_extension("pg_trgm")
6
+
5
7
  <% if use_schema? -%>
6
8
  reversible do |r|
7
9
  r.up { execute("CREATE SCHEMA <%= schema %>") }
@@ -15,22 +17,27 @@ class CreateE621Tables < ActiveRecord::Migration<%= migration_version %>
15
17
  t.string(:group_name)
16
18
  t.boolean(:is_active, null: false)
17
19
  t.boolean(:is_locked, null: false)
18
- t.bigint(:linked_user_id)
20
+ t.bigint(:linked_user_id, index: true)
19
21
  t.string(:name, null: false, index: { unique: true })
20
22
  t.text(:other_names, array: true, null: false, default: [])
21
23
  t.datetime(:updated_at, null: false)
22
- t.text(:urls, array: true, null: false, default: [])
24
+ t.text(:urls)
25
+ t.index("group_name gin_trgm_ops", using: :gin)
26
+ t.index("name gin_trgm_ops", using: :gin)
23
27
  end
24
28
 
25
29
  create_table(<%= table_ref("bulk_update_requests") %>, id: :bigint, default: nil, force: :cascade) do |t|
26
- t.bigint(:approver_id)
30
+ t.bigint(:approver_id, index: true)
27
31
  t.datetime(:created_at, null: false)
28
- t.bigint(:forum_topic_id)
32
+ t.bigint(:forum_topic_id, index: true)
33
+ t.bigint(:forum_post_id, index: true)
29
34
  t.text(:script, null: false)
30
35
  t.string(:status, null: false, index: true)
31
36
  t.string(:title)
32
37
  t.datetime(:updated_at, null: false)
33
38
  t.bigint(:user_id, null: false, index: true)
39
+ t.index("script gin_trgm_ops", using: :gin)
40
+ t.index("title gin_trgm_ops", using: :gin)
34
41
  end
35
42
 
36
43
  create_table(<%= table_ref("pools") %>, id: :bigint, default: nil, force: :cascade) do |t|
@@ -40,12 +47,14 @@ class CreateE621Tables < ActiveRecord::Migration<%= migration_version %>
40
47
  t.text(:description, null: false)
41
48
  t.boolean(:is_active, null: false)
42
49
  t.string(:name, null: false, index: true)
43
- t.bigint(:post_ids, array: true, null: false, default: [])
50
+ t.bigint(:post_ids, array: true, null: false, default: [], index: { using: :gin })
44
51
  t.datetime(:updated_at)
52
+ t.index("description gin_trgm_ops", using: :gin)
53
+ t.index("name gin_trgm_ops", using: :gin)
45
54
  end
46
55
 
47
56
  create_table(<%= table_ref("posts") %>, id: :bigint, default: nil, force: :cascade) do |t|
48
- t.bigint(:approver_id)
57
+ t.bigint(:approver_id, index: true)
49
58
  t.bigint(:change_seq, null: false)
50
59
  t.integer(:comment_count, null: false)
51
60
  t.datetime(:created_at, null: false)
@@ -58,59 +67,70 @@ class CreateE621Tables < ActiveRecord::Migration<%= migration_version %>
58
67
  t.integer(:image_height, null: false)
59
68
  t.integer(:image_width, null: false)
60
69
  t.boolean(:is_deleted, null: false, index: true)
61
- t.boolean(:is_flagged, null: false)
62
- t.boolean(:is_note_locked, null: false)
63
- t.boolean(:is_pending, null: false)
64
- t.boolean(:is_rating_locked, null: false)
65
- t.boolean(:is_status_locked, null: false)
70
+ t.boolean(:is_flagged, null: false, index: true)
71
+ t.boolean(:is_note_locked, null: false, index: true)
72
+ t.boolean(:is_pending, null: false, index: true)
73
+ t.boolean(:is_rating_locked, null: false, index: true)
74
+ t.boolean(:is_status_locked, null: false, index: true)
66
75
  t.text(:locked_tags, null: false)
67
76
  t.string(:md5, index: { unique: true }, null: false)
68
- t.bigint(:parent_id)
77
+ t.bigint(:parent_id, index: true)
69
78
  t.string(:rating, null: false, index: true)
70
79
  t.integer(:score, null: false)
71
- t.text(:sources, array: true, null: false, default: [])
72
- t.text(:tags, array: true, null: false, default: [])
80
+ t.text(:source, null: false)
81
+ t.text(:tag_string, null: false)
73
82
  t.integer(:up_score, null: false)
74
- t.datetime(:updated_at)
83
+ t.datetime(:updated_at, index: true)
75
84
  t.bigint(:uploader_id, index: true)
85
+ t.index("description gin_trgm_ops", using: :gin)
86
+ t.index("source gin_trgm_ops", using: :gin)
87
+ t.index("tag_string gin_trgm_ops", using: :gin)
76
88
  end
77
89
 
78
90
  create_table(<%= table_ref("post_replacements") %>, id: :bigint, default: nil, force: :cascade) do |t|
79
- t.bigint(:approver_id)
91
+ t.bigint(:approver_id, index: true)
80
92
  t.datetime(:created_at, null: false)
81
93
  t.bigint(:creator_id, null: false, index: true)
82
- t.string(:file_ext, null: false)
83
- t.string(:file_name, null: false)
84
- t.bigint(:file_size, null: false)
85
- t.integer(:image_height, null: false)
86
- t.integer(:image_width, null: false)
87
- t.string(:md5, null: false)
94
+ t.string(:file_ext, null: false, index: true)
95
+ t.string(:file_name, null: false, index: true)
96
+ t.bigint(:file_size, null: false, index: true)
97
+ t.integer(:image_height, null: false, index: true)
98
+ t.integer(:image_width, null: false, index: true)
99
+ t.string(:md5, null: false, index: true)
88
100
  t.bigint(:post_id, null: false, index: true)
89
101
  t.text(:reason, null: false)
90
102
  t.text(:source)
91
103
  t.string(:status, null: false, index: true)
92
104
  t.datetime(:updated_at, null: false)
105
+ t.index("reason gin_trgm_ops", using: :gin)
106
+ t.index("source gin_trgm_ops", using: :gin)
93
107
  end
94
108
 
95
109
  create_table(<%= table_ref("post_versions") %>, id: :bigint, default: nil, force: :cascade) do |t|
96
110
  t.text(:added_locked_tags, array: true, null: false, default: [])
97
111
  t.text(:added_tags, array: true, null: false, default: [])
98
112
  t.text(:description)
99
- t.boolean(:description_changed, null: false)
113
+ t.boolean(:description_changed, null: false, index: true)
100
114
  t.text(:locked_tags)
101
- t.boolean(:parent_changed, null: false)
115
+ t.boolean(:parent_changed, null: false, index: true)
102
116
  t.bigint(:parent_id)
117
+ t.bigint(:post_id, null: false, index: true)
103
118
  t.string(:rating)
104
- t.boolean(:rating_changed, null: false)
119
+ t.boolean(:rating_changed, null: false, index: true)
105
120
  t.text(:reason)
106
121
  t.text(:removed_locked_tags, array: true, null: false, default: [])
107
122
  t.text(:removed_tags, array: true, null: false, default: [])
108
123
  t.text(:source)
109
- t.boolean(:source_changed, null: false)
124
+ t.boolean(:source_changed, null: false, index: true)
110
125
  t.text(:tags)
111
126
  t.datetime(:updated_at, null: false, index: true)
112
- t.bigint(:updater_id, null: false, index: true)
113
- t.integer(:version, null: false)
127
+ t.bigint(:updater_id, index: true)
128
+ t.integer(:version, null: false, index: true)
129
+ t.index("description gin_trgm_ops", using: :gin)
130
+ t.index("locked_tags gin_trgm_ops", using: :gin)
131
+ t.index("reason gin_trgm_ops", using: :gin)
132
+ t.index("source gin_trgm_ops", using: :gin)
133
+ t.index("tags gin_trgm_ops", using: :gin)
114
134
  end
115
135
 
116
136
  create_table(<%= table_ref("tag_aliases") %>, id: :bigint, default: nil, force: :cascade) do |t|
@@ -118,6 +138,9 @@ class CreateE621Tables < ActiveRecord::Migration<%= migration_version %>
118
138
  t.string(:consequent_name, null: false, index: true)
119
139
  t.datetime(:created_at)
120
140
  t.string(:status, null: false, index: true)
141
+ t.index(%i[status antecedent_name])
142
+ t.index("antecedent_name gin_trgm_ops", using: :gin)
143
+ t.index("consequent_name gin_trgm_ops", using: :gin)
121
144
  end
122
145
 
123
146
  create_table(<%= table_ref("tag_implications") %>, id: :bigint, default: nil, force: :cascade) do |t|
@@ -125,22 +148,34 @@ class CreateE621Tables < ActiveRecord::Migration<%= migration_version %>
125
148
  t.string(:consequent_name, null: false, index: true)
126
149
  t.datetime(:created_at)
127
150
  t.string(:status, null: false, index: true)
151
+ t.index(%i[status consequent_name])
152
+ t.index(%i[status antecedent_name])
153
+ t.index("antecedent_name gin_trgm_ops", using: :gin)
154
+ t.index("consequent_name gin_trgm_ops", using: :gin)
128
155
  end
129
156
 
130
157
  create_table(<%= table_ref("tags") %>, id: :bigint, default: nil, force: :cascade) do |t|
131
158
  t.string(:category, null: false, index: true)
132
159
  t.string(:name, null: false, index: { unique: true })
133
- t.integer(:post_count, null: false)
160
+ t.integer(:post_count, null: false, index: { order: { post_count: :desc } })
161
+ t.index(%i[category post_count], order: { post_count: :desc })
162
+ t.index("name gin_trgm_ops", using: :gin)
134
163
  end
135
164
 
136
165
  create_table(<%= table_ref("wiki_pages") %>, id: :bigint, default: nil, force: :cascade) do |t|
137
- t.text(:body, null: false)
166
+ t.text(:body, null: false, index: true)
138
167
  t.datetime(:created_at, null: false)
139
- t.bigint(:creator_id, index: true)
140
- t.boolean(:is_locked, null: false)
168
+ t.bigint(:creator_id, null: false, index: true)
169
+ t.boolean(:is_locked, null: false, index: true)
141
170
  t.string(:title, null: false, index: { unique: true })
142
- t.datetime(:updated_at)
143
- t.bigint(:uploader_id)
171
+ t.datetime(:updated_at, null: false)
172
+ t.bigint(:updater_id, index: true)
173
+ t.index("body gin_trgm_ops", using: :gin)
174
+ t.index("title gin_trgm_ops", using: :gin)
175
+ end
176
+
177
+ create_table(<%= table_ref("row_counts") %>, primary_key: :table_name, id: :string, force: :cascade) do |t|
178
+ t.bigint(:count, null: false, default: 0)
144
179
  end
145
180
  end
146
181
  end
@@ -13,5 +13,14 @@ module ActiveRecord
13
13
 
14
14
  sig { params(attributes: T::Array[T::Hash[Symbol, T.untyped]], kwargs: T.untyped).returns(T.untyped) }
15
15
  def self.upsert_all(attributes, **kwargs); end
16
+
17
+ sig { params(value: T.untyped).void }
18
+ def self.primary_key=(value); end
19
+
20
+ sig { params(kwargs: T.untyped).returns(T.untyped) }
21
+ def self.find_by(**kwargs); end
22
+
23
+ sig { params(kwargs: T.untyped).returns(T.untyped) }
24
+ def self.where(**kwargs); end
16
25
  end
17
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: e621_export_downloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donovan_DMC
@@ -86,6 +86,7 @@ files:
86
86
  - lib/e621/post.rb
87
87
  - lib/e621/post_replacement.rb
88
88
  - lib/e621/post_version.rb
89
+ - lib/e621/row_count.rb
89
90
  - lib/e621/tag.rb
90
91
  - lib/e621/tag_alias.rb
91
92
  - lib/e621/tag_implication.rb