Skip to content

Discussion: /public/avatar and /:sharing-id/recipients/:index/avatar #3679

@Peltoche

Description

@Peltoche

Hi!

I would like to propose some improvement for the initial avatar system. This issue is created in order to discuss around the subject.

Context

The endpoints /public/avatar and /:sharing-id/recipients/:index/avatar are both used to retrieve a user avatar. Those avatar pic are png files with a round of color and 1 or 2 letters in it. They are looking a lot like the ones generated by this service.

Those endpoints are called to illustrate the users avatar inside the "Share" column in drive and inside the "Share" pop-in used to manage the sharing rules.

In order to generate those png files the convert binary from ImageMagick is called and then cached inside a cache service in order to improve the performances.

Issue

IMHO there is several issues with this process that can be improved:

  1. Using the convert binary force a external dependency to ImageMagick and this is a really big library.
  2. The convert command need a write/read into the filesystem and so it require an access to the filesystem.
  3. The call to an external binary and the access to the FS cost a lot in CPU and time. This is why a cache is required.
  4. The PNG format use rasterization which can be relatively heavy compared to another encodings

Proposed improvements

Do not use those endpoints

You already have a component in you ui librairy that does generate icons without any call to the server. This could be the easiest way to remove an http call, reduce the load on server side and reduce the latency on client side.

Use ajstarks/svgo in order to render an svg

After some tests I have successfully replaced the png generation with convert by the use of a full Go natif library generating an svg. Those change seems to resolve all the issues listed above:

  1. There is no need to use the convert binary anymore so no more dependencies.
  2. There is no more need to access the filesysteme.
  3. The performances are greatly improved, to the point that I guess the cache would not be required anymore
  4. By using SVG format I have successfully reduced the icon size from 3.3KB for the PNG file to 303B for the SVG.

Bonus point: With the SVG format you are using vectorization so your icon would have a perfect resolution whatever the size.

If you are interested I can propose you a PR with a "svgo" implementation for the initial generation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions