{"id":25343749,"url":"https://github.com/j3rn/saturn","last_synced_at":"2025-07-11T21:34:31.817Z","repository":{"id":276837892,"uuid":"930369641","full_name":"J3RN/saturn","owner":"J3RN","description":"A child-eating monster; a library to help you find and eliminate N+1 queries.","archived":false,"fork":false,"pushed_at":"2025-02-10T17:45:44.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T14:46:52.616Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/J3RN.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-10T14:25:53.000Z","updated_at":"2025-02-10T17:45:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"469e5f56-62ad-42a6-be81-5e246e8de416","html_url":"https://github.com/J3RN/saturn","commit_stats":null,"previous_names":["j3rn/saturn"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/J3RN/saturn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J3RN%2Fsaturn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J3RN%2Fsaturn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J3RN%2Fsaturn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J3RN%2Fsaturn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/J3RN","download_url":"https://codeload.github.com/J3RN/saturn/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J3RN%2Fsaturn/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264902824,"owners_count":23681123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-14T10:58:07.192Z","updated_at":"2025-07-11T21:34:31.775Z","avatar_url":"https://github.com/J3RN.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Saturn\n\nA child-eating monster; a library to help you find and eliminate N+1 queries.\n\n## Usage\n\nIn order for Saturn to collect query data, it first must be [installed](#installation).  Once that is completed, you may use the following functions:\n\nBy default, Saturn starts disabled (i.e. not collecting query data) to save memory.  When you'd like to start collecting query data, run:\n\n```elixir\nSaturn.enable()\n```\n\nYou can also configure Saturn to be enabled at start-up using the `enable` key of its configuration:\n\n```elixir\nconfig :saturn, enable: true\n```\n\nTo stop collecting query data, run:\n\n```elixir\nSaturn.disable()\n```\n\nOnce you have collected some data, you can query the most-made queries:\n\n```elixir\niex\u003e Saturn.report()\nQuery: \"SELECT DISTINCT o0.\\\"queue\\\" FROM \\\"public\\\".\\\"oban_jobs\\\" AS o0 WHERE (o0.\\\"state\\\" = 'available') AND (NOT (o0.\\\"queue\\\" IS NULL))\"\nCount: 100\nStacktrace:\n  lib/ecto/repo/supervisor.ex:162: Ecto.Repo.Supervisor.tuplet/2\n  lib/my_app/repo.ex:2: MyApp.Repo.all/2\n  lib/oban/plugins/stager.ex:131: Oban.Plugins.Stager.notify_queues/1\n  lib/oban/plugins/stager.ex:98: Oban.Plugins.Stager.-check_leadership_and_stage/1-fun-0-/1\n  lib/ecto/adapters/sql.ex:1202: Ecto.Adapters.SQL.-checkout_or_transaction/4-fun-0-/3\n  ...\n#=\u003e :ok\n```\n\nInvoking `Saturn.report()` as `Saturn.report(:count)` is equivalent; the argument defaults to `:count`.\n\nSaturn also supports querying by time:\n\n```elixir\niex\u003e Saturn.report(:time)\nQuery: \"SELECT DISTINCT o0.\\\"queue\\\" FROM \\\"public\\\".\\\"oban_jobs\\\" AS o0 WHERE (o0.\\\"state\\\" = 'available') AND (NOT (o0.\\\"queue\\\" IS NULL))\"\nTime: 157 ms\nStacktrace:\n  lib/ecto/repo/supervisor.ex:162: Ecto.Repo.Supervisor.tuplet/2\n  lib/my_app/repo.ex:2: MyApp.Repo.all/2\n  lib/oban/plugins/stager.ex:131: Oban.Plugins.Stager.notify_queues/1\n  lib/oban/plugins/stager.ex:98: Oban.Plugins.Stager.-check_leadership_and_stage/1-fun-0-/1\n  lib/ecto/adapters/sql.ex:1202: Ecto.Adapters.SQL.-checkout_or_transaction/4-fun-0-/3\n  ...\n#=\u003e :ok\n```\n\nLastly, Saturn supports a prof-style output (a la `eprof`, `fprof`, etc) to help you identify cost centers:\n\n```elixir\niex\u003e Saturn.report(:prof)\nSource                                                                   Count %Count     Time %Time\nSaturn.fake/1                                                                2     66   246.91    95\n  SELECT * FROM users;                                                       2     66   246.91    95\nSaturn.foobar/2                                                              1     33    12.35     4\n  Saturn.Foobar.do_thing/3                                                   1     33    12.35     4\n    SELECT * FROM users WHERE id = 5;                                        1     33    12.35     4\n```\n\n\nIf you want to clear all recorded queries, invoke `Saturn.clear/0`:\n\n```elixir\nSaturn.clear()\n#=\u003e :ok\n```\n\n## Installation\n\nThe package can be installed by adding `saturn` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:saturn, git: \"git@github.com:instinctscience/saturn.git\"}\n  ]\nend\n```\n\nNext, your application needs to be configured to send Ecto telemetry events to Saturn:\n\n```elixir\n# lib/myapp_web/telemetry.ex\n\n:ok =\n  :telemetry.attach(\n    \"saturn-aggregator\",\n    [:myapp, :repo, :query],\n    \u0026Saturn.handle_query/4,\n    nil\n  )\n```\n\n**Remember to change `:myapp` to the actual name of your app!**\n\nFinally, in order for Saturn to collect and report stacktraces, Ecto needs to be configured to include stacktraces in its telemetry events:\n\n```elixir\n# config/dev.exs\n\nconfig :myapp, :repo,\n  username: \"postgres\",\n  password: \"postgres\",\n  # etc\n  stacktrace: true\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj3rn%2Fsaturn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj3rn%2Fsaturn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj3rn%2Fsaturn/lists"}