• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

signdict / website / ac791a6a79ac45bb1fb32e214c33c7890f845e69

04 Oct 2025 07:53PM UTC coverage: 90.727%. First build
ac791a6a79ac45bb1fb32e214c33c7890f845e69

Pull #1660

github

bitboxer
More deprecations
Pull Request #1660: Update a few things

55 of 61 new or added lines in 26 files covered. (90.16%)

1223 of 1348 relevant lines covered (90.73%)

86.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.21
/lib/sign_dict_web/controllers/backend/csv_export_suggestions_controller.ex
1
defmodule SignDictWeb.Backend.CSVExportSuggestionsController do
2
  use SignDictWeb, :controller
3

4
  alias SignDict.Domain
5

6
  def show(conn = %{assigns: %{current_user: current_user}}, _params) do
7
    if Canada.Can.can?(current_user, "statistic", %SignDict.Entry{}) do
1✔
8
      do_export(conn)
1✔
9
    else
10
      conn
11
      |> put_flash(:info, gettext("You cannot view this page."))
×
NEW
12
      |> redirect(to: Router.Helpers.backend_dashboard_path(conn, :index))
×
13
    end
14
  end
15

16
  defp do_export(conn) do
17
    conn =
1✔
18
      conn
19
      |> put_resp_header("content-disposition", "attachment; filename=statistic_suggestions.csv")
20
      |> put_resp_content_type("text/csv")
21
      |> send_chunked(200)
22

23
    {:ok, conn} =
1✔
24
      Repo.transaction(fn ->
25
        conn.host
1✔
26
        |> Domain.for()
27
        |> build_export_query()
28
        |> chunk_data(conn)
1✔
29
      end)
30

31
    conn
1✔
32
  end
33

34
  defp chunk_data(data, conn) do
35
    Enum.reduce_while(data, conn, fn data, conn ->
1✔
36
      case chunk(conn, data) do
2✔
37
        {:ok, conn} ->
2✔
38
          {:cont, conn}
39

40
        {:error, :closed} ->
×
41
          {:halt, conn}
42
      end
43
    end)
44
  end
45

46
  def build_export_query(domain, batch_size \\ 500) do
47
    query = """
1✔
48
      select word, description, trim(both '"' from to_json(inserted_at)::text)
49
        from suggestions
50
        where domain_id = $1
51
    """
52

53
    csv_header = [["Word", "Description", "Time"]]
1✔
54

55
    Ecto.Adapters.SQL.stream(Repo, query, [domain.id], max_rows: batch_size)
1✔
56
    |> Stream.flat_map(fn item ->
57
      item.rows
1✔
58
    end)
59
    |> (fn stream -> Stream.concat(csv_header, stream) end).()
1✔
60
    |> CSV.encode()
1✔
61
  end
62
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc