summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMark Felder <feld@feld.me>2024-10-29 16:00:18 -0400
committerMark Felder <feld@feld.me>2024-10-29 16:00:18 -0400
commitd2de251c4d018c7d517d399d7d5e0e20d853972f (patch)
tree919ca21f13782085fe6a0ec0cafecf96a4733023 /lib
parent6099a94dbc26c9f86e340769af34c7b28725d831 (diff)
downloadpleroma-d2de251c4d018c7d517d399d7d5e0e20d853972f.tar.gz
pleroma-d2de251c4d018c7d517d399d7d5e0e20d853972f.zip
Pleroma.Upload.Filter.Dedupe: sharding directory structure
Dedupe now uses a three-level sharding directory structure to improve performance when many files are uploaded and stored on a filesystem instead of an object store. (note: Minio still affected as it still uses a traditional filesystem) This does not help if you already have hundreds of thousands of files uploaded. The media URLs are permanently part of the activity so the files cannot be relocated. A motivated user could write a tool to move the files and perhaps write an Nginx or equivalent redirect to make the files still accessible, but that is beyond the scope of this change.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/upload/filter/dedupe.ex10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/pleroma/upload/filter/dedupe.ex b/lib/pleroma/upload/filter/dedupe.ex
index ef793d390..7b278d299 100644
--- a/lib/pleroma/upload/filter/dedupe.ex
+++ b/lib/pleroma/upload/filter/dedupe.ex
@@ -17,8 +17,16 @@ defmodule Pleroma.Upload.Filter.Dedupe do
|> Base.encode16(case: :lower)
filename = shasum <> "." <> extension
- {:ok, :filtered, %Upload{upload | id: shasum, path: filename}}
+
+ {:ok, :filtered, %Upload{upload | id: shasum, path: shard_path(filename)}}
end
def filter(_), do: {:ok, :noop}
+
+ @spec shard_path(String.t()) :: String.t()
+ def shard_path(
+ <<a::binary-size(2), b::binary-size(2), c::binary-size(2), _::binary>> = filename
+ ) do
+ Path.join([a, b, c, filename])
+ end
end