From e35b1810431c8621df97fc5d19a7a180a9bc37fb Mon Sep 17 00:00:00 2001 From: Mayel de Borniol Date: Tue, 29 Oct 2024 09:04:29 +0000 Subject: [PATCH] misc --- Dockerfile.release | 3 +- docker-compose.yml | 3 +- flavours/classic/repo/seeds.exs | 96 +++++++++++++++++++++------------ justfile | 7 ++- 4 files changed, 70 insertions(+), 39 deletions(-) diff --git a/Dockerfile.release b/Dockerfile.release index c7bee38b78..08106944fe 100644 --- a/Dockerfile.release +++ b/Dockerfile.release @@ -128,7 +128,8 @@ COPY --link lib lib # workaround for compilation errors (eg. "could not load module Needle.UID due to reason :unavailable") RUN MIX_ENV=prod mix deps.clean needle_uid jason poison bonfire --build -RUN MIX_ENV=prod mix deps.compile --include-children needle_uid needle_ulid paper_trail +RUN MIX_ENV=prod mix deps.compile --include-children needle_uid needle_ulid  +# paper_trail # compile protocols (attempted fix for 'could not load module Poison.Encoder due to reason :unavailable') # RUN MIX_ENV=prod mix compile.protocols diff --git a/docker-compose.yml b/docker-compose.yml index 804ce52074..1fcf92f598 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,5 @@ # A Dockerfile for development/testing - -version: "3.5" +# version: "3.5" services: web: diff --git a/flavours/classic/repo/seeds.exs b/flavours/classic/repo/seeds.exs index 6a6daef06a..fb0e7cb056 100644 --- a/flavours/classic/repo/seeds.exs +++ b/flavours/classic/repo/seeds.exs @@ -6,9 +6,20 @@ import Bonfire.Me.Fake import Bonfire.Social.Fake import Bonfire.Posts.Fake +# num_users = 100 +# num_objects = 100000 +# num_sub_objects = 50 +num_users = 3 +num_objects = 10 +num_sub_objects = 10 + System.put_env("INVITE_ONLY", "false") System.put_env("SEARCH_INDEXING_DISABLED", "true") +Application.put_env(:bonfire_common, Bonfire.Common.AntiSpam, + service: Bonfire.Common.AntiSpam.Mock +) + # if the user has configured an admin user for the seeds, insert it. case {System.get_env("ADMIN_USER", "root"), System.get_env("ADMIN_PASSWORD", "")} do {u, p} when p != "" -> @@ -21,61 +32,76 @@ case {System.get_env("ADMIN_USER", "root"), System.get_env("ADMIN_PASSWORD", "") end # create some users -users = for _ <- 1..3, do: fake_user!() +users = for _ <- 1..num_users, do: fake_user!() random_user = fn -> Faker.Util.pick(users) end # start fake threads threads = - for _ <- 1..10 do - thread = fake_post!(random_user.()) - comment = fake_comment!(random_user.(), thread) - comment = fake_comment!(random_user.(), comment) + for i <- 1..num_objects do + thread = + case Faker.Util.pick(1..3) do + 1 -> + fake_post!(random_user.()) + + 2 -> + fake_post!(random_user.(), "public", %{ + post_content: %{ + summary: "test #{i} with #hashtag" + } + }) + + 3 -> + fake_post!(random_user.(), "public", %{ + post_content: %{ + summary: "@#{e(random_user.(), :character, :username, nil)} test mention #{i}" + } + }) + end + + comments = for i <- 1..num_sub_objects, do: fake_comment!(random_user.(), thread) + + _sub_comment = + for i <- 1..num_sub_objects, do: fake_comment!(random_user.(), Faker.Util.pick(comments)) + thread - end ++ - for i <- 1..4 do - fake_post!(random_user.(), "public", %{ - post_content: %{ - html_body: "test #{i} with #hashtag" - } - }) - end ++ - for i <- 1..4 do - mention = random_user.() - - fake_post!(random_user.(), "public", %{ - post_content: %{ - html_body: "@#{e(mention, :character, :username, nil)} test mention #{i}" - } - }) - end + end # random_thread = fn -> Faker.Util.pick(threads) end # define some tags/categories -if(Bonfire.Common.Extend.extension_enabled?(Bonfire.Classify.Simulate)) do - for _ <- 1..2 do +if( + Bonfire.Common.Extend.extension_enabled?(Bonfire.UI.Groups) or + Bonfire.Common.Extend.extension_enabled?(Bonfire.UI.Topics) +) do + for _ <- 1..num_objects do category = Bonfire.Classify.Simulate.fake_category!(random_user.()) - _subcategory = Bonfire.Classify.Simulate.fake_category!(random_user.(), category) + + for i <- 1..num_sub_objects do + subcategory = Bonfire.Classify.Simulate.fake_category!(random_user.(), category) + + for i <- 1..num_sub_objects do + _subsubcategory = Bonfire.Classify.Simulate.fake_category!(random_user.(), subcategory) + end + end end end # define some geolocations if(Bonfire.Common.Extend.extension_enabled?(Bonfire.Geolocate.Simulate)) do - for _ <- 1..2, + for _ <- 1..num_objects, do: Bonfire.Geolocate.Simulate.fake_geolocation!(random_user.()) end # define some units if(Bonfire.Common.Extend.extension_enabled?(Bonfire.Quantify.Simulate)) do - for _ <- 1..2 do - _unit1 = Bonfire.Quantify.Simulate.fake_unit!(random_user.()) - _unit2 = Bonfire.Quantify.Simulate.fake_unit!(random_user.()) + for _ <- 1..num_objects do + Bonfire.Quantify.Simulate.fake_unit!(random_user.()) end end # conduct some fake economic activities if(Bonfire.Common.Extend.extension_enabled?(ValueFlows.Simulate)) do - for _ <- 1..2 do + for _ <- 1..num_objects do user = random_user.() action_id = ValueFlows.Simulate.action_id() @@ -84,7 +110,7 @@ if(Bonfire.Common.Extend.extension_enabled?(ValueFlows.Simulate)) do _proposal = ValueFlows.Simulate.fake_proposal!(user) end - for _ <- 1..2 do + for _ <- 1..num_objects do user = random_user.() _process_spec = ValueFlows.Simulate.fake_process_specification!(user) @@ -105,10 +131,12 @@ if(Bonfire.Common.Extend.extension_enabled?(ValueFlows.Simulate)) do # define some geolocations if(Bonfire.Common.Extend.extension_enabled?(Bonfire.Geolocate.Simulate)) do - places = for _ <- 1..2, do: Bonfire.Geolocate.Simulate.fake_geolocation!(random_user.()) + places = + for _ <- 1..num_objects, do: Bonfire.Geolocate.Simulate.fake_geolocation!(random_user.()) + random_place = fn -> Faker.Util.pick(places) end - for _ <- 1..2 do + for _ <- 1..num_objects do # define some intents with geolocation _intent = ValueFlows.Simulate.fake_intent!( @@ -157,7 +185,7 @@ if(Bonfire.Common.Extend.extension_enabled?(ValueFlows.Simulate)) do unit1 = Bonfire.Quantify.Simulate.fake_unit!(random_user.()) unit2 = Bonfire.Quantify.Simulate.fake_unit!(random_user.()) - for _ <- 1..2 do + for _ <- 1..num_objects do action_id = ValueFlows.Simulate.action_id() # define some intents with measurements intent = diff --git a/justfile b/justfile index 90fb3ff99e..cda27ce55e 100644 --- a/justfile +++ b/justfile @@ -842,7 +842,10 @@ rebuild: init _db-dump docker_compose compose_args="": -mv data/db_dump.sql data/db_dump.archive.sql - just docker-compose -f {{docker_compose}} {{compose_args}} exec db /bin/bash -c "PGPASSWORD=$POSTGRES_PASSWORD pg_dump --username $POSTGRES_USER $POSTGRES_DB" > data/db_dump.sql + just _db-shell {{docker_compose}} pg_dump {{compose_args}} " > data/db_dump.sql" + +_db-shell docker_compose cmd="psql" compose_args="" extra_args="": + just docker-compose -f {{docker_compose}} {{compose_args}} exec --user $POSTGRES_USER db /bin/bash -c "PGPASSWORD=$POSTGRES_PASSWORD {{cmd}} --username $POSTGRES_USER" {{extra_args}} # Run a specific command in the container (if used), eg: `just cmd messclt` or `just cmd time` or `just cmd "echo hello"` @cmd *args='': init docker-stop-web @@ -863,7 +866,7 @@ shell: -docker rm $WEB_CONTAINER @docker *args='': - export $(./tool-versions-to-env.sh 3 | xargs) && export $(grep -v '^#' .tool-versions.env | xargs) && export ELIXIR_DOCKER_IMAGE="${ELIXIR_VERSION}-erlang-${ERLANG_VERSION}-alpine-${ALPINE_VERSION}" && echo $ELIXIR_DOCKER_IMAGE && docker $@ + export $(./tool-versions-to-env.sh 3 | xargs) && export $(grep -v '^#' .tool-versions.env | xargs) && export ELIXIR_DOCKER_IMAGE="${ELIXIR_VERSION}-erlang-${ERLANG_VERSION}-alpine-${ALPINE_VERSION}" && docker $@ @docker-compose *args='': just docker compose $@