EddieHubCommunity / EddieHubLive

Map to show EddieHub contributors
https://live.eddiehub.io
MIT License
47 stars 39 forks source link

Only add user to map once #31

Closed eddiejaoude closed 2 years ago

eddiejaoude commented 2 years ago

Description

Currently the user is added to the map multiple times (only seen once), this will get slow

Maybe check if the user is on the map already, if so do nothing

Screenshots

No response

Additional information

No response

brijeshsoni1300 commented 2 years ago

image so we are considering this as a same? not sure but is soln like? changing setEvents([...events,data]) to setEvents([...new Set([...events, data])]) work? so it will remove those above duplicate entries

eddiejaoude commented 2 years ago

This issue is about the map, each event in the list also re-adds the user to the map, but the user is only seen once of the map as they are at the same location

I think we need to have 2 data arrays for the events

  1. for the list https://github.com/EddieHubCommunity/EddieHubLive/blob/main/src/App.js#L19
  2. for the map https://github.com/EddieHubCommunity/EddieHubLive/blob/main/src/App.js#L23 but for the map, before adding to the array we need to check if the user already exists, if so do not add it (or use a Set as you suggested)
brijeshsoni1300 commented 2 years ago

okay so,

  1. instead <Map events={events} /> could we pass <Map events={[...new Set(events)]} /> to remove duplicate entries? or
  2. could we create another list of users which is a set of users and update that list every time we get new data and add user to that list if not exist already? or still, I m not getting it properly?
eddiejaoude commented 2 years ago

oh interesting! I like your idea <Map events={[...new Set(events)]} />, it is much cleaner than the way I was thinking, let's try that 👍

You got it correct, great work @brijeshsoni1300 🔥

eddiejaoude commented 2 years ago

The issue still remains

Screenshot 2022-07-11 at 19 49 45
eddiejaoude commented 2 years ago

Testing this locally with...


if (
   !uniqueUsers.find(
      (user) => user.githubUsername._id === data.githubUsername._id
   )
) {
   setUniqueUsers([...uniqueUsers, data]);
}
brijeshsoni1300 commented 2 years ago

what if we have one function which filters our list to have only one entry of object per GitHub URL

  function removeDuplicateUsersFromEvents(){
    let uniqueEvents = [];
    events.forEach(event => {
      if(!uniqueEvents.some(uniqueEvent => uniqueEvent.githubUserURL === event.githubUserURL)){
        uniqueEvents.push(event);
      }
    }
    );
    console.log(events)
    console.log("uniqueEvents"+uniqueEvents)
    return uniqueEvents;
  }

and then passing it to Map <Map events={removeDuplicateUsersFromEvents()} />

well I checked it locally, it's filtering for your URL there were 23 entries in the events list but one entry after removing dups in uniqueEvents list

brijeshsoni1300 commented 2 years ago

Testing this locally with...

if (!uniqueUsers.includes(data.githubUsername._id)) {
   setUniqueUsers([...uniqueUsers, data]);
}

actually in those List of objects we have repeated ids so it will cause dups again image

brijeshsoni1300 commented 2 years ago

Testing this locally with...

if (
   !uniqueUsers.find(
      (user) => user.githubUsername._id === data.githubUsername._id
   )
) {
   setUniqueUsers([...uniqueUsers, data]);
}

okay got it, we are filtering it using Github id so that will be the same for the same user let me try this