pleroma.database fill_old_hashtags: Add month_limit argument
This commit is contained in:
parent
18b536c176
commit
d0c2479710
|
@ -93,12 +93,14 @@ Can be safely re-run
|
|||
|
||||
## Fill hashtags for old objects
|
||||
|
||||
Migrate hashags fields for old objects, from now to `months_limit` months.
|
||||
|
||||
```sh tab="OTP"
|
||||
./bin/pleroma_ctl database fill_old_hashtags
|
||||
./bin/pleroma_ctl database fill_old_hashtags <months_limit>
|
||||
```
|
||||
|
||||
```sh tab="From Source"
|
||||
mix pleroma.database fill_old_hashtags
|
||||
mix pleroma.database fill_old_hashtags <months_limit>
|
||||
```
|
||||
|
||||
## Vacuum the database
|
||||
|
|
|
@ -128,17 +128,24 @@ def run(["fix_likes_collections"]) do
|
|||
|> Stream.run()
|
||||
end
|
||||
|
||||
def run(["fill_old_hashtags"]) do
|
||||
def run(["fill_old_hashtags", month_limit]) do
|
||||
import Ecto.Query
|
||||
|
||||
start_pleroma()
|
||||
|
||||
month_limit = String.to_integer(month_limit)
|
||||
|
||||
if month_limit < 1 do
|
||||
shell_error("Invalid `month_limit` argument, needs to be greater than 1")
|
||||
else
|
||||
time_limit = DateTime.utc_now() |> Timex.shift(months: -month_limit)
|
||||
|
||||
from(
|
||||
o in Object,
|
||||
where: fragment("(?)->>'hashtags' is null", o.data),
|
||||
where: fragment("(?)->>'tag' != '[]'", o.data),
|
||||
select: %{id: o.id, tag: fragment("(?)->>'tag'", o.data)},
|
||||
order_by: [:desc, o.id]
|
||||
where: o.inserted_at < ^time_limit,
|
||||
select: %{id: o.id, tag: fragment("(?)->>'tag'", o.data)}
|
||||
)
|
||||
|> Pleroma.Repo.chunk_stream(200, :batches)
|
||||
|> Stream.each(fn objects ->
|
||||
|
@ -170,6 +177,7 @@ def run(["fill_old_hashtags"]) do
|
|||
end)
|
||||
|> Stream.run()
|
||||
end
|
||||
end
|
||||
|
||||
def run(["vacuum", args]) do
|
||||
start_pleroma()
|
||||
|
|
Loading…
Reference in New Issue