diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000..2a06c1efb5 Binary files /dev/null and b/.DS_Store differ diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000000..c6dd253a54 Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/assets/.DS_Store b/app/assets/.DS_Store new file mode 100644 index 0000000000..647eb62ed2 Binary files /dev/null and b/app/assets/.DS_Store differ diff --git a/app/assets/javascripts/.DS_Store b/app/assets/javascripts/.DS_Store new file mode 100644 index 0000000000..f331010991 Binary files /dev/null and b/app/assets/javascripts/.DS_Store differ diff --git a/public/.DS_Store b/public/.DS_Store new file mode 100644 index 0000000000..7e67e88fad Binary files /dev/null and b/public/.DS_Store differ diff --git a/public/images/.DS_Store b/public/images/.DS_Store new file mode 100644 index 0000000000..dc1589872b Binary files /dev/null and b/public/images/.DS_Store differ diff --git a/public/images/emoji/.DS_Store b/public/images/emoji/.DS_Store new file mode 100644 index 0000000000..85483c535e Binary files /dev/null and b/public/images/emoji/.DS_Store differ diff --git a/script/bulk_import/generic_bulk.rb b/script/bulk_import/generic_bulk.rb index 0c773f8c2e..17072f9941 100644 --- a/script/bulk_import/generic_bulk.rb +++ b/script/bulk_import/generic_bulk.rb @@ -23,14 +23,15 @@ class BulkImport::Generic < BulkImport::Base end def execute - import_categories - import_users - import_user_emails + # import_categories + # import_users + # import_user_emails #import_single_sign_on_records - import_topics - import_posts - import_topic_allowed_users - import_likes + # import_topics + # import_posts + # import_topic_allowed_users + # import_likes + import_user_stats end def import_categories @@ -229,6 +230,50 @@ class BulkImport::Generic < BulkImport::Base end end + def import_user_stats + puts "Importing user stats..." + + users = @db.execute(<<~SQL) + WITH posts_counts AS (SELECT COUNT(p.id) as count, p.user_id FROM posts p GROUP BY p.user_id), + topic_counts AS (SELECT COUNT(t.id) as count, t.user_id FROM topics t GROUP BY t.user_id), + first_post AS (SELECT MIN(p.created_at) as created_at, p.user_id FROM posts p GROUP BY p.user_id ORDER BY p.created_at ASC) + SELECT u.id as user_id, u.created_at, pc.count as posts, tc.count as topics, fp.created_at as first_post + FROM users u + JOIN posts_counts pc ON u.id = pc.user_id + JOIN topic_counts tc ON u.id = tc.user_id + JOIN first_post fp on u.id = fp.user_id + SQL + + create_user_stats(users) do |row| + user = { + imported_id: row["user_id"], + imported_user_id: row["user_id"], + new_since: to_datetime(row["created_at"]), + post_count: row["posts"], + topic_count: row["topics"], + first_post_created_at: to_datetime(row["first_post"]) + } + + likes_received = @db.execute(<<~SQL) + SELECT COUNT(l.id) as likes_received FROM likes l join posts p on l.post_id = p.id WHERE p.user_id = #{row["user_id"]} + SQL + + if likes_received + user[:likes_received] = row["likes_received"] + end + + likes_given = @db.execute(<<~SQL) + SELECT COUNT(l.id) as likes_given FROM likes l WHERE l.user_id = #{row["user_id"]} + SQL + + if likes_given + user[:likes_given] = row["likes_given"] + end + + user + end + end + def create_connection(path) sqlite = SQLite3::Database.new(path, results_as_hash: true) sqlite.busy_timeout = 60000 # 60 seconds