diff options
author | Maksim Pechnikov <parallel588@gmail.com> | 2020-09-16 09:47:18 +0300 |
---|---|---|
committer | Maksim Pechnikov <parallel588@gmail.com> | 2020-09-16 09:47:18 +0300 |
commit | 599f8bb152ca0669d17baa5f313f00f0791209b6 (patch) | |
tree | 9bc4e08bdc2a0c78ba773775dc11a17c9e0350d1 /lib/pleroma/repo.ex | |
parent | c74fad9e06cdb272a1378082908448f7f0b592ac (diff) | |
download | pleroma-599f8bb152ca0669d17baa5f313f00f0791209b6.tar.gz |
RepoStreamer.chunk_stream -> Repo.chunk_stream
Diffstat (limited to 'lib/pleroma/repo.ex')
-rw-r--r-- | lib/pleroma/repo.ex | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/pleroma/repo.ex b/lib/pleroma/repo.ex index a75610879..4524bd5e2 100644 --- a/lib/pleroma/repo.ex +++ b/lib/pleroma/repo.ex @@ -49,6 +49,20 @@ defmodule Pleroma.Repo do end end + @doc """ + Returns a lazy enumerable that emits all entries from the data store matching the given query. + + `returns_as` use to group records. use the `batches` option to fetch records in bulk. + + ## Examples + + # fetch records one-by-one + iex> Pleroma.Repo.chunk_stream(Pleroma.Activity.Queries.by_actor(ap_id), 500) + + # fetch records in bulk + iex> Pleroma.Repo.chunk_stream(Pleroma.Activity.Queries.by_actor(ap_id), 500, :batches) + """ + @spec chunk_stream(Ecto.Query.t(), integer(), atom()) :: Enumerable.t() def chunk_stream(query, chunk_size, returns_as \\ :one) do # We don't actually need start and end funcitons of resource streaming, # but it seems to be the only way to not fetch records one-by-one and |