adrianhajdin / project_mern_memories

This is a code repository for the corresponding video tutorial. Using React, Node.js, Express & MongoDB you'll learn how to build a Full Stack MERN Application - from start to finish. The App is called "Memories" and it is a simple social media app that allows users to post interesting events that happened in their lives.
https://youtube.com/playlist?list=PL6QREj8te1P7VSwhrMf3D3Xt4V6_SRkhu
5k stars 1.84k forks source link

Slow Loading Screen while fetching posts from database #86

Closed warmachine028 closed 1 year ago

warmachine028 commented 2 years ago

Posts are loading very slow after adding chat section in 5th part. Is there any way to make it fast ?

LameckMeshack commented 2 years ago

Sure am even thinking of using MongoDB compass than atlas

shubhamy4ever commented 2 years ago

mongo db compass is gui for either local database or else cluster(atlas) which means u can't use compass as local database because then the memories project database will be unaccesible to others users and will not be on cloud

LameckMeshack commented 2 years ago

Sure ...but I only use for development during deployment I'll connect it to the Atlas

On Thu, 3 Mar 2022, 5:49 pm Shubham Yadav, @.***> wrote:

mongo db compass is gui for either local database or else cluster(atlas) which means u can't use compass as local database because then the memories project database will be unaccesible to others users and will not be on cloud

— Reply to this email directly, view it on GitHub https://github.com/adrianhajdin/project_mern_memories/issues/86#issuecomment-1058117431, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARK6XYW6ZDYTMQ36YENMW6TU6DGPVANCNFSM5MCSRN6Q . You are receiving this because you commented.Message ID: @.***>

shubhamy4ever commented 2 years ago

ok

abdullahalnomandev commented 2 years ago

I'm fetching the same issue. It takes around 1-2 minutes to fetch. how to solve it?

warmachine028 commented 2 years ago

I'm fetching the same issue. It takes around 1-2 minutes to fetch. how to solve it?

*Facing

warmachine028 commented 1 year ago

I have tried a different solution to fix this, it's redundant but clever.

  1. All post images are compressed(<1mb) and a thumbnail (<100kb) is generated on Creation and Updation.
  2. The thumbnails instead of the actual image are stored in the post document.
  3. The actual compressed media are stored in a different collection named Media.
  4. During Bulk fetching of posts we are only fetching the documents from Post collection which has lower size putting less stress on server. Also we can compromise on image quality in this scenario since we are seeing the small thumbnails anyway. This leads to a significantly faster fetching time.
  5. Whereas during fetching an individual post we replace the thumbnail with actual post image from the Media collection.
  6. This solved the slower fetching issue and retains the image quality.
  7. Drawback: yes we have to make 2 queries and the data is now redundant in the database but we have to make some compromises to improve and fix this major issue.

Here is my repo link. I have a detailed ERD in the README too.