Just streamlined my dev environment and switched from SQLite3 to PG so it's the same on my production environment.
The same working code that I had before is now taking much, MUCH more time than it did before.
Haven't changed anything except installing pg.
Before PG:
Processing by CollectionsController#show as HTML
Parameters: {"keyword"=>"cat and dog towel", "id"=>"37"}
Collection Load (0.2ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = ? LIMIT ? [["id", 37], ["LIMIT", 1]]
Seller Load (0.2ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = ? LIMIT ? [["id", 13], ["LIMIT", 1]]
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
(0.1ms) begin transaction
(0.1ms) commit transaction
Search Load (0.2ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = ? LIMIT ? [["term", "cat and dog towel"], ["LIMIT", 1]]
Listing Load (1.4ms) SELECT DISTINCT "listings".* FROM "listings" INNER JOIN "listings_searches" ON "listings"."id" = "listings_searches"."listing_id" WHERE "listings_searches"."search_id" = ? ORDER BY "listings"."id" ASC LIMIT ? [["search_id", 775], ["LIMIT", 1]]
Search Load (0.3ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = ? ORDER BY "searches"."id" ASC LIMIT ? [["term", "Beach Towel"], ["LIMIT", 1]]
(0.1ms) begin transaction
Search Exists (0.2ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = ? LIMIT ? [["term", "Beach Towel"], ["LIMIT", 1]]
SQL (0.5ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES (?, ?, ?) [["term", "Beach Towel"], ["created_at", "2018-06-18 12:47:58.519223"], ["updated_at", "2018-06-18 12:47:58.519223"]]
(7.0ms) commit transaction
Item Exists (0.3ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = ? AND "items"."collection_id" = 37 LIMIT ? [["search_id", 776], ["LIMIT", 1]]
(0.1ms) begin transaction
Collection Load (0.1ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = ? LIMIT ? [["id", 37], ["LIMIT", 1]]
Item Exists (0.2ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = ? AND "items"."search_id" = 776 LIMIT ? [["collection_id", 37], ["LIMIT", 1]]
SQL (2.3ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["collection_id", 37], ["search_id", 776], ["created_at", "2018-06-18 12:47:58.540021"], ["updated_at", "2018-06-18 12:47:58.540021"]]
(6.2ms) commit transaction
Started GET "/sellers/16" for 127.0.0.1 at 2018-06-18 15:48:00 +0300
Processing by SellersController#show as HTML
Parameters: {"id"=>"16"}
Search Load (5.5ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = ? ORDER BY "searches"."id" ASC LIMIT ? [["term", "Bath Towel"], ["LIMIT", 1]]
(0.1ms) begin transaction
Search Exists (0.2ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = ? LIMIT ? [["term", "Bath Towel"], ["LIMIT", 1]]
SQL (1.4ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES (?, ?, ?) [["term", "Bath Towel"], ["created_at", "2018-06-18 12:48:01.250699"], ["updated_at", "2018-06-18 12:48:01.250699"]]
Seller Load (0.3ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = ? LIMIT ? [["id", 16], ["LIMIT", 1]]
(9.6ms) commit transaction
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
Item Exists (0.3ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = ? AND "items"."collection_id" = 37 LIMIT ? [["search_id", 777], ["LIMIT", 1]]
(0.1ms) begin transaction
Collection Load (0.3ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = ? LIMIT ? [["id", 37], ["LIMIT", 1]]
Item Exists (0.2ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = ? AND "items"."search_id" = 777 LIMIT ? [["collection_id", 37], ["LIMIT", 1]]
SQL (1.0ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["collection_id", 37], ["search_id", 777], ["created_at", "2018-06-18 12:48:01.285942"], ["updated_at", "2018-06-18 12:48:01.285942"]]
Shop Load (8.8ms) SELECT "shops".* FROM "shops" WHERE "shops"."seller_id" = ? ORDER BY "shops"."id" DESC LIMIT ? [["seller_id", 16], ["LIMIT", 1]]
(40.2ms) commit transaction
Rendering sellers/show.html.erb within layouts/application
(0.4ms) SELECT COUNT(*) FROM "listings" WHERE "listings"."shop_id" = 12
Listing Load (0.4ms) SELECT "listings".* FROM "listings" WHERE "listings"."shop_id" = 12 LIMIT ? OFFSET ? [["LIMIT", 24], ["OFFSET", 0]]
Rendered sellers/show.html.erb within layouts/application (4.8ms)
Rendered layouts/_shim.html.erb (0.4ms)
Rendered layouts/_rails_default.html.erb (93.9ms)
Rendered layouts/_meta.html.erb (0.3ms)
Seller Exists (0.3ms) SELECT 1 AS one FROM "sellers" WHERE "sellers"."user_id" = ? LIMIT ? [["user_id", 1], ["LIMIT", 1]]
Seller Load (0.3ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."user_id" = ? ORDER BY "sellers"."id" DESC LIMIT ? [["user_id", 1], ["LIMIT", 1]]
Rendered layouts/_header.html.erb (5.5ms)
Seller Load (0.3ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."user_id" = ? [["user_id", 1]]
Shop Load (0.3ms) SELECT "shops".* FROM "shops" WHERE "shops"."seller_id" = ? ORDER BY "shops"."id" DESC LIMIT ? [["seller_id", 13], ["LIMIT", 1]]
CACHE Shop Load (0.0ms) SELECT "shops".* FROM "shops" WHERE "shops"."seller_id" = ? ORDER BY "shops"."id" DESC LIMIT ? [["seller_id", 16], ["LIMIT", 1]]
Rendered layouts/_sidebar.html.erb (7.3ms)
Rendered layouts/_end_sidebar.html.erb (0.4ms)
Rendered layouts/_footer.html.erb (0.4ms)
Completed 200 OK in 212ms (Views: 120.5ms | ActiveRecord: 12.3ms)
After PG:
Started POST "/collections/1/item/choose.25" for 127.0.0.1 at 2018-06-18 16:56:12 +0300
Processing by ItemsController#choose as
Parameters: {"authenticity_token"=>"11+Rpf2qXEKhQ5vBJLWie2EBg1b2Dtrw8iIgoLwXyvake7+myDrVErcqTwNcPYAZ5xs+zFKXaJjwM7fTakXaoA==", "collection_id"=>"1"}
Collection Load (0.4ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Seller Load (0.6ms) SELECT "sellers".* FROM "sellers" WHERE "sellers"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Load (0.3ms) SELECT "items".* FROM "items" WHERE "items"."id" = $1 LIMIT $2 [["id", 25], ["LIMIT", 1]]
(0.1ms) BEGIN
Collection Load (0.5ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Search Load (0.9ms) SELECT "searches".* FROM "searches" WHERE "searches"."id" = $1 LIMIT $2 [["id", 31], ["LIMIT", 1]]
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND ("items"."id" != $2) AND "items"."search_id" = 31 LIMIT $3 [["collection_id", 1], ["id", 25], ["LIMIT", 1]]
SQL (0.8ms) UPDATE "items" SET "chosen" = $1, "updated_at" = $2 WHERE "items"."id" = $3 [["chosen", "t"], ["updated_at", "2018-06-18 13:56:12.465841"], ["id", 25]]
(2.7ms) COMMIT
(0.4ms) BEGIN
SQL (0.6ms) UPDATE "collections" SET "keyword" = $1, "updated_at" = $2 WHERE "collections"."id" = $3 [["keyword", "Bookish Candles"], ["updated_at", "2018-06-18 13:56:12.473173"], ["id", 1]]
(1.5ms) COMMIT
Search Load (0.6ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "Bookish Candles"], ["LIMIT", 1]]
Listing Load (4.1ms) SELECT DISTINCT "listings".* FROM "listings" INNER JOIN "listings_searches" ON "listings"."id" = "listings_searches"."listing_id" WHERE "listings_searches"."search_id" = $1 ORDER BY "listings"."id" ASC LIMIT $2 [["search_id", 31], ["LIMIT", 3]]
Search Load (0.7ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "soy candles"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.8ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "soy candles"], ["LIMIT", 1]]
SQL (0.6ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "soy candles"], ["created_at", "2018-06-18 13:56:12.491262"], ["updated_at", "2018-06-18 13:56:12.491262"]]
(2.3ms) COMMIT
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 46], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (1.3ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 46 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (1.0ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 46], ["created_at", "2018-06-18 13:56:12.504381"], ["updated_at", "2018-06-18 13:56:12.504381"]]
(1.1ms) COMMIT
Search Load (0.8ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "book candle"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.5ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "book candle"], ["LIMIT", 1]]
SQL (0.5ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "book candle"], ["created_at", "2018-06-18 13:56:14.812727"], ["updated_at", "2018-06-18 13:56:14.812727"]]
(2.8ms) COMMIT
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 47], ["LIMIT", 1]]
(0.1ms) BEGIN
Collection Load (1.0ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 47 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.5ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 47], ["created_at", "2018-06-18 13:56:14.825865"], ["updated_at", "2018-06-18 13:56:14.825865"]]
(1.4ms) COMMIT
Search Load (1.0ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "literary gifts"], ["LIMIT", 1]]
(0.4ms) BEGIN
Search Exists (0.7ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "literary gifts"], ["LIMIT", 1]]
SQL (0.7ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "literary gifts"], ["created_at", "2018-06-18 13:56:17.776368"], ["updated_at", "2018-06-18 13:56:17.776368"]]
(2.4ms) COMMIT
Item Exists (0.8ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 48], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (1.6ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.8ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 48 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (1.1ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 48], ["created_at", "2018-06-18 13:56:17.790424"], ["updated_at", "2018-06-18 13:56:17.790424"]]
(1.2ms) COMMIT
Search Load (0.7ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "book candles"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.7ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "book candles"], ["LIMIT", 1]]
SQL (0.6ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "book candles"], ["created_at", "2018-06-18 13:56:20.872076"], ["updated_at", "2018-06-18 13:56:20.872076"]]
(1.4ms) COMMIT
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 49], ["LIMIT", 1]]
(0.1ms) BEGIN
Collection Load (0.6ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 49 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.8ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 49], ["created_at", "2018-06-18 13:56:20.883450"], ["updated_at", "2018-06-18 13:56:20.883450"]]
(2.3ms) COMMIT
Search Load (0.9ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "literary candles"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.5ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "literary candles"], ["LIMIT", 1]]
SQL (0.8ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "literary candles"], ["created_at", "2018-06-18 13:56:22.523896"], ["updated_at", "2018-06-18 13:56:22.523896"]]
(1.4ms) COMMIT
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 50], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (0.7ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.9ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 50 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.9ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 50], ["created_at", "2018-06-18 13:56:22.536553"], ["updated_at", "2018-06-18 13:56:22.536553"]]
(2.2ms) COMMIT
Search Load (0.9ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "soy candle"], ["LIMIT", 1]]
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 18], ["LIMIT", 1]]
Search Load (0.6ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "8oz candles"], ["LIMIT", 1]]
(0.3ms) BEGIN
Search Exists (0.6ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "8oz candles"], ["LIMIT", 1]]
SQL (0.5ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "8oz candles"], ["created_at", "2018-06-18 13:56:25.455733"], ["updated_at", "2018-06-18 13:56:25.455733"]]
(2.4ms) COMMIT
Item Exists (0.8ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 51], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (0.7ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 51 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (1.0ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 51], ["created_at", "2018-06-18 13:56:25.468089"], ["updated_at", "2018-06-18 13:56:25.468089"]]
(1.2ms) COMMIT
Search Load (0.7ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "handmade soy candles"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.5ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "handmade soy candles"], ["LIMIT", 1]]
SQL (0.5ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "handmade soy candles"], ["created_at", "2018-06-18 13:56:27.445609"], ["updated_at", "2018-06-18 13:56:27.445609"]]
(1.3ms) COMMIT
Item Exists (1.1ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 52], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (0.5ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 52 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.6ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 52], ["created_at", "2018-06-18 13:56:27.457050"], ["updated_at", "2018-06-18 13:56:27.457050"]]
(2.5ms) COMMIT
Search Load (0.7ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "bookish candle"], ["LIMIT", 1]]
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 13], ["LIMIT", 1]]
Search Load (0.5ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "bookish candles"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.5ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "bookish candles"], ["LIMIT", 1]]
SQL (1.0ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "bookish candles"], ["created_at", "2018-06-18 13:56:29.102682"], ["updated_at", "2018-06-18 13:56:29.102682"]]
(1.6ms) COMMIT
Item Exists (0.8ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 53], ["LIMIT", 1]]
(0.3ms) BEGIN
Collection Load (0.5ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.5ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 53 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.6ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 53], ["created_at", "2018-06-18 13:56:29.114736"], ["updated_at", "2018-06-18 13:56:29.114736"]]
(2.1ms) COMMIT
Search Load (1.0ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "personalized gifts"], ["LIMIT", 1]]
(0.2ms) BEGIN
Search Exists (0.8ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "personalized gifts"], ["LIMIT", 1]]
SQL (0.8ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "personalized gifts"], ["created_at", "2018-06-18 13:56:30.446268"], ["updated_at", "2018-06-18 13:56:30.446268"]]
(1.5ms) COMMIT
Item Exists (1.0ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 54], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (0.9ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 54 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.8ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 54], ["created_at", "2018-06-18 13:56:30.459078"], ["updated_at", "2018-06-18 13:56:30.459078"]]
(2.2ms) COMMIT
Search Load (0.7ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "personalized gift"], ["LIMIT", 1]]
(0.3ms) BEGIN
Search Exists (0.5ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "personalized gift"], ["LIMIT", 1]]
SQL (0.6ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "personalized gift"], ["created_at", "2018-06-18 13:56:32.460438"], ["updated_at", "2018-06-18 13:56:32.460438"]]
(2.5ms) COMMIT
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 55], ["LIMIT", 1]]
(0.2ms) BEGIN
Collection Load (0.7ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.7ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 55 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.7ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 55], ["created_at", "2018-06-18 13:56:32.474614"], ["updated_at", "2018-06-18 13:56:32.474614"]]
(1.1ms) COMMIT
Search Load (0.8ms) SELECT "searches".* FROM "searches" WHERE "searches"."term" = $1 ORDER BY "searches"."id" ASC LIMIT $2 [["term", "book smell"], ["LIMIT", 1]]
(0.5ms) BEGIN
Search Exists (0.8ms) SELECT 1 AS one FROM "searches" WHERE "searches"."term" = $1 LIMIT $2 [["term", "book smell"], ["LIMIT", 1]]
SQL (0.7ms) INSERT INTO "searches" ("term", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["term", "book smell"], ["created_at", "2018-06-18 13:56:34.573441"], ["updated_at", "2018-06-18 13:56:34.573441"]]
(1.3ms) COMMIT
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."search_id" = $1 AND "items"."collection_id" = 1 LIMIT $2 [["search_id", 56], ["LIMIT", 1]]
(0.1ms) BEGIN
Collection Load (1.4ms) SELECT "collections".* FROM "collections" WHERE "collections"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Item Exists (0.6ms) SELECT 1 AS one FROM "items" WHERE "items"."collection_id" = $1 AND "items"."search_id" = 56 LIMIT $2 [["collection_id", 1], ["LIMIT", 1]]
SQL (0.6ms) INSERT INTO "items" ("collection_id", "search_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["collection_id", 1], ["search_id", 56], ["created_at", "2018-06-18 13:56:34.585728"], ["updated_at", "2018-06-18 13:56:34.585728"]]
(2.5ms) COMMIT
Redirected to http://localhost:3000/collections/1
Completed 302 Found in 24422ms (ActiveRecord: 153.5ms)
The amount of items I'm inserting varies but even between many different examples, PG always takes longer, even though when looking at those two logs I posted, it seems like SQLite3 is taking longer per transaction.
Is this normal or is there something I can do to optimize it?
Thanks!
Looks like ActiveRecord is responding pretty quickly for both databases:
Sqlite: ActiveRecord: 12.3ms
Postgres: ActiveRecord: 153.5ms
While Postgres is certainly higher, I would think both of those response times would be acceptable, and that they would vary slightly each time you hit that action.
You do, however, have some sort of redirect taking place 302 Redirected to http://localhost:3000/collections/1 that seems to be adding a bunch of time to the request.
You might try making sure that there are no scripts on that page that are gumming up the works. Also, you might make sure that the indexes have been applied to your Postgres database, and also make sure your collections page doesn't have any n+1 queries.
Hard to say more with the limited information given in the question,
When I create a new account using google authentication, it creates a account and also do the login automaticaly.
If I click logout and later login again, with the same google account, I can't login...
I get no error message :(
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
#user = User.from_omniauth(request.env["omniauth.auth"])
if #user.persisted?
sign_in_and_redirect #user, event: :authentication
set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
def google_oauth2
#user = User.from_omniauth(request.env["omniauth.auth"])
if #user.persisted?
sign_in_and_redirect #user, event: :authentication
set_flash_message(:notice, :success, kind: "Google") if is_navigational_format?
else
session["devise.google_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
Another informations.
Here is the log when the autentication / account creation works:
Started GET "/auth/google_oauth2" for 177.207.232.141 at 2016-10-23 23:47:31 +0000
Started GET "/auth/google_oauth2/callback?state=1f3b3124e0264c1dabb3f40059d9a15a9da524553e0ec5dc&code=4/ZjqBwsoXJJXncItmMDuwPssw0ooT1RwnNjkRIfilQYc" for 177.207.232.141 at 2016-10-23 23:47:33 +0000
Processing by OmniauthCallbacksController#google_oauth2 as HTML
Parameters: {"state"=>"1f3b3124e0264c1dabb3f40059d9a15a9da524553e0ec5dc", "code"=>"4/ZjqBwsoXJJXncItmMDuwPssw0ooT1RwnNjkRIfilQYc"}
[1m[35mSubdomain Load (27.7ms)[0m SELECT "subdomains".* FROM "subdomains" WHERE "subdomains"."address" = $1 LIMIT 1 [["address", "yoga"]]
[1m[36mDomain Load (27.5ms)[0m [1mSELECT "domains".* FROM "domains" WHERE "domains"."address" = $1 LIMIT 1[0m [["address", "smartmarket.io"]]
[1m[35mUser Load (28.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."provider" = $1 AND "users"."uid" = $2 ORDER BY "users"."id" ASC LIMIT 1 [["provider", "google_oauth2"], ["uid", "110174173081848856467"]]
[1m[36m (27.7ms)[0m [1mBEGIN[0m
[1m[35mUser Exists (27.8ms)[0m SELECT 1 AS one FROM "users" WHERE "users"."email" = 'diogowernik#gmail.com' LIMIT 1
[1m[36mUser Exists (27.8ms)[0m [1mSELECT 1 AS one FROM "users" WHERE "users"."email" = 'diogowernik#gmail.com' LIMIT 1[0m
[1m[35mSQL (27.9ms)[0m INSERT INTO "users" ("provider", "uid", "name", "email", "image", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["provider", "google_oauth2"], ["uid", "really?"], ["name", "Diogo Wernik"], ["email", "diogowernik#gmail.com"], ["image", "https://lh6.googleusercontent.com/-vXjHRteu8BY/AAAAAAAAAAI/AAAAAAAAB3A/_oEJPVq8h8o/photo.jpg"], ["encrypted_password", "$2a$10$6CIsOntiZxoLQfyUTfskiuys3P4u6.M0O4h/4S5zoW7EpN2KgX4Re"], ["created_at", "2016-10-23 23:47:34.023034"], ["updated_at", "2016-10-23 23:47:34.023034"]]
[1m[36mSQL (28.1ms)[0m [1mINSERT INTO "profiles" ("name", "kind", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"[0m [["name", "Diogo Wernik"], ["kind", "blog"], ["user_id", 5], ["created_at", "2016-10-23 23:47:34.082199"], ["updated_at", "2016-10-23 23:47:34.082199"]]
[1m[35mSQL (28.4ms)[0m INSERT INTO "user_main_profiles" ("profile_id", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["profile_id", 5], ["user_id", 5], ["created_at", "2016-10-23 23:47:34.140877"], ["updated_at", "2016-10-23 23:47:34.140877"]]
[1m[36mUserMainProfile Load (27.7ms)[0m [1mSELECT "user_main_profiles".* FROM "user_main_profiles" WHERE "user_main_profiles"."user_id" = $1 LIMIT 1[0m [["user_id", 5]]
[1m[35m (28.1ms)[0m COMMIT
[1m[36mUser Load (27.9ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1[0m [["id", 1]]
[1m[35m (27.5ms)[0m BEGIN
[1m[36mSQL (27.9ms)[0m [1mUPDATE "users" SET "last_sign_in_at" = $1, "current_sign_in_at" = $2, "last_sign_in_ip" = $3, "current_sign_in_ip" = $4, "sign_in_count" = $5, "updated_at" = $6 WHERE "users"."id" = $7[0m [["last_sign_in_at", "2016-10-23 23:47:34.301029"], ["current_sign_in_at", "2016-10-23 23:47:34.301029"], ["last_sign_in_ip", "177.207.232.141/32"], ["current_sign_in_ip", "177.207.232.141/32"], ["sign_in_count", 1], ["updated_at", "2016-10-23 23:47:34.329926"], ["id", 5]]
[1m[35m (28.0ms)[0m COMMIT
Redirected to http://yoga.smartmarket.io/
Completed 302 Found in 636ms (ActiveRecord: 418.1ms)
[1m[36m (27.5ms)[0m [1mBEGIN[0m
[1m[35mSQL (27.7ms)[0m DELETE FROM "sessions" WHERE "sessions"."id" = $1 [["id", 11]]
[1m[36m (27.9ms)[0m [1mCOMMIT[0m
Here is when i logout and try to login again with the same account
Started GET "/auth/google_oauth2" for 177.207.232.141 at 2016-10-23 23:51:13 +0000
Started GET "/auth/google_oauth2/callback?state=ca339595a33e9e192c274a78450400a02e7edfd7f7ebb937&code=4/bQ59Fm5Fcxv_vWtBlFpMAwMoY6iig8J6bZGWFKboZms" for 177.207.232.141 at 2016-10-23 23:51:14 +0000
Processing by OmniauthCallbacksController#google_oauth2 as HTML
Parameters: {"state"=>"ca339595a33e9e192c274a78450400a02e7edfd7f7ebb937", "code"=>"4/bQ59Fm5Fcxv_vWtBlFpMAwMoY6iig8J6bZGWFKboZms"}
[1m[35mSubdomain Load (27.6ms)[0m SELECT "subdomains".* FROM "subdomains" WHERE "subdomains"."address" = $1 LIMIT 1 [["address", "yoga"]]
[1m[36mDomain Load (27.5ms)[0m [1mSELECT "domains".* FROM "domains" WHERE "domains"."address" = $1 LIMIT 1[0m [["address", "smartmarket.io"]]
[1m[35mUser Load (27.9ms)[0m SELECT "users".* FROM "users" WHERE "users"."provider" = $1 AND "users"."uid" = $2 ORDER BY "users"."id" ASC LIMIT 1 [["provider", "google_oauth2"], ["uid", "110174173081848856467"]]
[1m[36m (27.7ms)[0m [1mBEGIN[0m
[1m[35mUser Exists (28.5ms)[0m SELECT 1 AS one FROM "users" WHERE "users"."email" = 'diogowernik#gmail.com' LIMIT 1
[1m[36mUser Exists (28.0ms)[0m [1mSELECT 1 AS one FROM "users" WHERE "users"."email" = 'diogowernik#gmail.com' LIMIT 1[0m
[1m[35m (27.8ms)[0m ROLLBACK
Redirected to http://yoga.smartmarket.io/sign_up
Completed 302 Found in 271ms (ActiveRecord: 195.0ms)
Started GET "/sign_up" for 177.207.232.141 at 2016-10-23 23:51:15 +0000
Processing by Devise::RegistrationsController#new as HTML
[1m[36mSubdomain Load (27.5ms)[0m [1mSELECT "subdomains".* FROM "subdomains" WHERE "subdomains"."address" = $1 LIMIT 1[0m [["address", "yoga"]]
[1m[35mDomain Load (27.7ms)[0m SELECT "domains".* FROM "domains" WHERE "domains"."address" = $1 LIMIT 1 [["address", "smartmarket.io"]]
Rendered devise/registrations/_social.erb (0.5ms)
Rendered devise/registrations/new.html.erb within layouts/application (2.0ms)
Rendered layouts/partials/_topnavbar.html.erb (0.4ms)
Rendered layouts/partials/_sidebar.html.erb (0.1ms)
Rendered layouts/partials/_footer.html.erb (0.0ms)
Rendered layouts/partials/_alerts.erb (0.1ms)
Completed 200 OK in 251ms (Views: 165.2ms | ActiveRecord: 83.0ms)
Started GET "/api/i18n/site-pt.json" for 177.207.232.141 at 2016-10-23 23:51:16 +0000
Processing by ApiController#i18n as JSON
Parameters: {"locale"=>"site-pt"}
Rendered app/assets/i18n/site-pt.json (0.1ms)
Completed 200 OK in 35ms (Views: 5.8ms | ActiveRecord: 27.9ms)
Started GET "/assets/fontawesome/fonts/fontawesome-webfont.woff2?v=4.5.0" for 177.207.232.141 at 2016-10-23 23:51:16 +0000
Started GET "/sign_up" for 177.207.232.141 at 2016-10-23 23:51:16 +0000
Processing by Devise::RegistrationsController#new as HTML
[1m[36mSubdomain Load (27.6ms)[0m [1mSELECT "subdomains".* FROM "subdomains" WHERE "subdomains"."address" = $1 LIMIT 1[0m [["address", "yoga"]]
[1m[35mDomain Load (27.5ms)[0m SELECT "domains".* FROM "domains" WHERE "domains"."address" = $1 LIMIT 1 [["address", "smartmarket.io"]]
Rendered devise/registrations/_social.erb (0.5ms)
Rendered devise/registrations/new.html.erb within layouts/application (2.2ms)
Rendered layouts/partials/_topnavbar.html.erb (0.4ms)
Rendered layouts/partials/_sidebar.html.erb (0.1ms)
Rendered layouts/partials/_footer.html.erb (0.0ms)
Rendered layouts/partials/_alerts.erb (0.1ms)
Completed 200 OK in 231ms (Views: 144.7ms | ActiveRecord: 83.0ms)
Here is the user.rb
class User < ActiveRecord::Base
include Userable
# include DeviseTokenAuth::Concerns::User
# Include default devise modules. Others available are:
# :lockable, :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable,
:validatable, :omniauthable # , :confirmable
validates :email, uniqueness: true
enum permission: [:guest, :admin]
after_create :create_profile!, :send_welcome_email!
before_validation :set_uid!
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.name = auth.info.name
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.image = auth.info.image
user.password = Devise.friendly_token[0, 20]
end
end
def main_profile
user_main_profile.try :profile
end
private
def set_uid!
self.uid = 'really?'
end
def create_profile!
profile = profiles.create(
name: name,
kind: 'blog'
)
create_user_main_profile(profile_id: profile.id)
end
def send_welcome_email!
UserMailer.delay.welcome(self.id)
end
end
What I can tell is that your INSERT:
[1m[35mSQL (27.9ms)[0m INSERT INTO "users" ("provider", "uid", "name", "email", "image", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["provider", "google_oauth2"], ["uid", "really?"], ["name", "Diogo Wernik"], ["email", "diogowernik#gmail.com"], ["image", "https://lh6.googleusercontent.com/-vXjHRteu8BY/AAAAAAAAAAI/AAAAAAAAB3A/_oEJPVq8h8o/photo.jpg"], ["encrypted_password", "$2a$10$6CIsOntiZxoLQfyUTfskiuys3P4u6.M0O4h/4S5zoW7EpN2KgX4Re"], ["created_at", "2016-10-23 23:47:34.023034"], ["updated_at", "2016-10-23 23:47:34.023034"]]
is passing field ["uid", "really?"] when it should be passing ["uid", "110174173081848856467"]
So when the user tries to log via Google, it searches:
SELECT "users".* FROM "users" WHERE "users"."provider" = $1 AND "users"."uid" = $2 ORDER BY "users"."id" ASC LIMIT 1 [["provider", "google_oauth2"], ["uid", "110174173081848856467"]]
Check your user.rb to see how omniauth is getting the variables or edit your post with the content.