+1
-1
app/importers/base_importer.rb
+1
-1
app/importers/base_importer.rb
+1
-1
app/importers/likes_importer.rb
+1
-1
app/importers/likes_importer.rb
+1
-1
app/importers/posts_importer.rb
+1
-1
app/importers/posts_importer.rb
+1
-1
app/importers/reposts_importer.rb
+1
-1
app/importers/reposts_importer.rb
+26
app/models/import.rb
+26
app/models/import.rb
···
9
validates_uniqueness_of :collection, scope: :user_id
10
11
scope :unfinished, -> { where('(started_from IS NOT NULL) OR (last_completed IS NULL)') }
12
+
13
+
IMPORT_END = Time.at(0)
14
+
15
+
def imported_until
16
+
return nil if cursor.nil? && last_completed.nil?
17
+
18
+
groups = case collection
19
+
when 'likes'
20
+
[:likes]
21
+
when 'reposts'
22
+
[:reposts]
23
+
when 'posts'
24
+
[:pins, :quotes]
25
+
end
26
+
27
+
newest_queued_items = groups.map { |g| user.send(g).where(queue: :import).order(:time).last }
28
+
newest_queued = newest_queued_items.compact.sort_by(&:time).last
29
+
30
+
if newest_queued
31
+
newest_queued.time
32
+
elsif fetched_until
33
+
fetched_until
34
+
else
35
+
IMPORT_END
36
+
end
37
+
end
38
end
+3
-16
app/models/user.rb
+3
-16
app/models/user.rb
···
50
end
51
52
def imported_until
53
-
return nil unless self.imports.exists?
54
-
55
-
oldest_imported_items = []
56
-
started = false
57
58
-
[:likes, :reposts, :pins, :quotes].each do |group|
59
-
if self.send(group).where(queue: :import).exists?
60
-
oldest_imported_items << self.send(group).where(queue: nil).order(:time).first
61
-
end
62
-
end
63
-
64
-
earliest_oldest = oldest_imported_items.compact.sort_by(&:time).last
65
-
66
-
if earliest_oldest
67
-
earliest_oldest.time
68
-
elsif self.imports.merge(Import.unfinished).exists?
69
nil
70
else
71
-
:end
72
end
73
end
74
+1
-1
app/server.rb
+1
-1
app/server.rb
+5
db/migrate/20251027134657_add_fetched_until_to_imports.rb
+5
db/migrate/20251027134657_add_fetched_until_to_imports.rb
+2
-1
db/schema.rb
+2
-1
db/schema.rb
···
10
#
11
# It's strongly recommended that you check this file into your version control system.
12
13
-
ActiveRecord::Schema[7.2].define(version: 2025_09_23_180153) do
14
# These are extensions that must be enabled in order to support this database
15
enable_extension "plpgsql"
16
···
25
t.datetime "started_from"
26
t.datetime "last_completed"
27
t.string "collection", limit: 20, null: false
28
t.index ["user_id", "collection"], name: "index_imports_on_user_id_and_collection", unique: true
29
end
30
···
10
#
11
# It's strongly recommended that you check this file into your version control system.
12
13
+
ActiveRecord::Schema[7.2].define(version: 2025_10_27_134657) do
14
# These are extensions that must be enabled in order to support this database
15
enable_extension "plpgsql"
16
···
25
t.datetime "started_from"
26
t.datetime "last_completed"
27
t.string "collection", limit: 20, null: false
28
+
t.datetime "fetched_until"
29
t.index ["user_id", "collection"], name: "index_imports_on_user_id_and_collection", unique: true
30
end
31