quazar

quazar

Why store ecto_arc field in database?

I am little bit confused about arc and ecto_arc using with phoenix. Suppose I have a schema “User” and it has avatar pic. Do I really need to create avatar string field or can I just get away with naming file consistently using id or uuid, ex.

  def filename(version, {_, scope}) do
    "avatar_#{scope.uuid}"
  end

def storage_dir(version, {file, scope}) do
  "uploads/images/#{scope.uuid}/"
end

It works but I am not sure it its best pratice. Also I have added boolean column (avatar_uploaded) to track if avatar is uploaded. I understand that boolean uses very few bytes compared to storing string and for a model with like million records this can really save some space. So should I do it? What pitfalls am I digging for myself?

Most Liked

NobbZ

NobbZ

String fields in a database, null or with a value, might still occupy the full space on disk that is defined as max. This is sometimes done by the DBMS as a measure of optimization (alignment of data on disk). Therefore usually just making the string fields nullable and treating null as nothing uploaded is probably the way that consumes the least space.

Last Post!

quazar

quazar

I think you misunderstood me. I meant if the file I am uploading will be renamed in def filename and this new file name is only dependent on scope.id. In that can do I need to store it in database at all? I mean id is not going to change whatsoever.

URL example on arc readme file. The url generated is not dependent on filename “selfie.png” at all, so why it needs to be there?

Avatar.url({"selfie.png", user}) #=> "https://bucket.s3.amazonaws.com/uploads/1/original.png"

Where Next?

Popular in Discussions Top

acrolink
How does the two languages compare when it comes to server side application development? Any experiences or ideas? Thank you.
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
RudManusachi
What configs will make sense to put to runtime.exs? – A bit of how I configure apps: I have generic configs in config/config.exs, dev...
New
fireproofsocks
I’ve been working on an Elixir project that has required a lot of scripting. I usually reach for Elixir because I like it more (and in th...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement