No working cache for avatar

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MaxDau
    Member
    • Nov 2022
    • 38

    No working cache for avatar

    Based on this post, I took a look at my log and discovered that I have larger blocks of simultaneous requests.

    Code:
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936277 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936278 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936275 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936280 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936282 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936284 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936283 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936286 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936287 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936288 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936289 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936290 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936291 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:18:56 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051936293 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942154 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942155 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942153 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942157 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942158 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942159 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942160 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942161 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942162 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942163 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942164 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942166 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942165 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942167 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942168 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:02 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051942170 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944944 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944942 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944943 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944946 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944945 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944947 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944948 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944949 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944951 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944953 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944954 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944956 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944955 HTTP/2.0" 200 456 "https://www.domain.work/"
    111.222.333.444 - - [03/Dec/2022:07:19:05 +0000] "GET /?entryPoint=avatar&size=small&id=1&t=1670051944958 HTTP/2.0" 200 456 "https://www.domain.work/"
    ​
    ​
    44 Requests in 9 seconds by 1 user.

    Although the avatar images have a cache header, each image is queried by the server. A look at the endpoint shows that such a simple request is painfully pulled through the CRM even though the file already exists ready for download. But more on that later.

    In the Avatar.php the value t / timestamp is not requested. Therefore, the parameter can (normally) be removed. I have tested this once.

    Click image for larger version

Name:	Screenshot_12_2500x.png
Views:	378
Size:	415.3 KB
ID:	85896

    After

    Click image for larger version

Name:	Screenshot_13_2500x.png
Views:	232
Size:	61.4 KB
ID:	85897


    Cache works, even when loading additional content no request is sent to the server.


    If you're already touching on the subject:

    Change from jpeg to webP
    Currently, the images are created in jpeg. webP has been supported by all common browsers for a long time. In my tests, the file size is about half as large.
    3.88kb jpeg -> 2.20kb webP

    Create images on upload, not on fetch
    If images are created and saved in the correct sizes when they are uploaded, you can actually handle all the requests outside the CRM.
    To be on the safe side, create a unique folder for avatars and then save the images in it with user_id.
    /uuid/userId_size.webp

    If you do not want to do without the access check, you can also keep the access point and set a 302 header after a successful check. Since the image will load in the cache anyway, a redirection would not be frequent.

    In any case, you can save a lot of unnecessary server load if you make a few adjustments here. The quickest and most effective fix would be to remove the timestamp from the request.​
  • yuri
    Member
    • Mar 2014
    • 8439

    #2
    You have either cache disabled or developer mode in Espo. Not a bug.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • MaxDau
      Member
      • Nov 2022
      • 38

      #3
      Originally posted by yuri
      You have either cache disabled or developer mode in Espo. Not a bug.
      Please check the request. Each Request is unique. How can u cache a unique request for an other unique request?
      You can see in the log and in my picture that t has a different value each time.

      Comment

      • yuri
        Member
        • Mar 2014
        • 8439

        #4
        That's because your Espo is in the developer mode or you have disabled cache in Espo settings.
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment

        • MaxDau
          Member
          • Nov 2022
          • 38

          #5
          Originally posted by yuri
          That's because your Espo is in the developer mode or you have disabled cache in Espo settings.
          Thats correct.

          Comment

          Working...