mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-11-20 08:30:59 +00:00
Merge branch 'hotfix/notification-migration' into 'develop'
Chunk the notification type backfill migration See merge request pleroma/pleroma!2653
This commit is contained in:
commit
83e5b95102
2 changed files with 29 additions and 1 deletions
|
@ -18,7 +18,7 @@ defmodule Pleroma.MigrationHelper.NotificationBackfill do
|
||||||
)
|
)
|
||||||
|
|
||||||
query
|
query
|
||||||
|> Repo.all()
|
|> Repo.chunk_stream(100)
|
||||||
|> Enum.each(fn notification ->
|
|> Enum.each(fn notification ->
|
||||||
type =
|
type =
|
||||||
notification.activity
|
notification.activity
|
||||||
|
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Repo do
|
||||||
adapter: Ecto.Adapters.Postgres,
|
adapter: Ecto.Adapters.Postgres,
|
||||||
migration_timestamps: [type: :naive_datetime_usec]
|
migration_timestamps: [type: :naive_datetime_usec]
|
||||||
|
|
||||||
|
import Ecto.Query
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
defmodule Instrumenter do
|
defmodule Instrumenter do
|
||||||
|
@ -78,6 +79,33 @@ defmodule Pleroma.Repo do
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def chunk_stream(query, chunk_size) 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
|
||||||
|
# have individual records be the elements of the stream, instead of
|
||||||
|
# lists of records
|
||||||
|
Stream.resource(
|
||||||
|
fn -> 0 end,
|
||||||
|
fn
|
||||||
|
last_id ->
|
||||||
|
query
|
||||||
|
|> order_by(asc: :id)
|
||||||
|
|> where([r], r.id > ^last_id)
|
||||||
|
|> limit(^chunk_size)
|
||||||
|
|> all()
|
||||||
|
|> case do
|
||||||
|
[] ->
|
||||||
|
{:halt, last_id}
|
||||||
|
|
||||||
|
records ->
|
||||||
|
last_id = List.last(records).id
|
||||||
|
{records, last_id}
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
fn _ -> :ok end
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defmodule Pleroma.Repo.UnappliedMigrationsError do
|
defmodule Pleroma.Repo.UnappliedMigrationsError do
|
||||||
|
|
Loading…
Reference in a new issue