MozillaFoundation / foundation.mozilla.org

Mozilla Foundation website
https://foundation.mozilla.org
Mozilla Public License 2.0
389 stars 153 forks source link

[Participate Page] Questions for Engineers #1650

Closed taisdesouzalessa closed 6 years ago

taisdesouzalessa commented 6 years ago

We would like to add a Pulse section in our new Participate page. Here is the comp for the section:

image

We have some questions regarding implementation:

  1. Does Pulse API give the client a way to query for latest projects with 1 or more Help Categories? We would like to list those projects on the right side, as in the comp.
  2. If 1 is possible, could we add ellipsis if help categories go beyond 1 line? E.g. "Common Voice" project (we don't want to display all help categories since there are too many so I added ellipsis instead).
  3. Could we add a dynamic number at the CTA button? "See [NUMBER] more projects" - [NUMBER] will vary depending on how many projects we have on Pulse.

cc: @xmatthewx

gideonthomas commented 6 years ago

Does Pulse API give the client a way to query for latest projects with 1 or more Help Categories? We would like to list those projects on the right side, as in the comp.

Yes, you can do that with /api/pulse/v2/entries/?help_type=Take%20Action. You can also add other help types to the query and it will end up being an OR query. For example, going to /api/pulse/v2/entries/?help_type=Take%20Action&help_type=Write%20documentation will return entries with Take Action OR Write documentation.

Edit: I was totally wrong about it being an OR query...it's definitely an AND query.

If 1 is possible, could we add ellipsis if help categories go beyond 1 line? E.g. "Common Voice" project (we don't want to display all help categories since there are too many so I added ellipsis instead).

That's a front-end issue but I don't see why not. We just need to determine a cut-off and add ellipsis there (although if you want to cut-off based on words and not characters, it's a bit more complicated).

Could we add a dynamic number at the CTA button? "See [NUMBER] more projects" - [NUMBER] will vary depending on how many projects we have on Pulse.

The API route (mentioned above) that you use to get the entries filtered by help type is paginated and therefore has a count property that you can use to get the total number of projects based on that help type. If you want a count of all entries regardless of help type, you could hit up the /api/pulse/v2/entries/ route without a filter and rely on the count value in that. However, I don't recommend doing that because it might cause performance issues. If you need this implemented in a performant way, we'll need to add that to the API.

xmatthewx commented 6 years ago

Does Pulse API give the client a way to query for latest projects with 1 or more Help Categories?

To clarify this @gideonthomas ... an OR query can work, but I wonder if will it strain the API. We query for all dozen help categories. We can heavily cache this – it doesn't need to update often. But I wonder if there's a more efficient NOT NULL. Not critical, just curious.

gideonthomas commented 6 years ago

We can probably add some indexing to the queries run by that route that will significantly reduce the load (if any) on the database. If we want to go even further, we can add a django cache layer on top of that which works with the indexes and caches data accordingly. But indexing is probably the first and best line of defense.

If we're worried about the server sending large amounts of data (vs. pulling it out of the database), we should add AWS Cloudfront for caching these routes (long-term, I think this is probably a good idea anyway as we increase traffic on the API).

xmatthewx commented 6 years ago

I don't expect this to be a particularly heavy hit route, so I wouldn't worry too much. It just seems very inefficient to write:

/v2/entries/?help_type=Attend &help_type=Create%20content &help_type=Code &help_type=Design &help_type=Fundraise &help_type=Join%20community &help_type=Localize%20&%20translate &help_type=Mentor &help_type=Plan%20&%20organize &help_type=Promote &help_type=Take%20Action &help_type=Test%20&%20feedback &help_type=Write%20documentation

instead of something easy to read, such as /v2/entries/?help_type=TRUE

gideonthomas commented 6 years ago

Ah so you want to just filter entries that have a help type? We'll have to add custom logic for that, but it seems doable.

xmatthewx commented 6 years ago

Great. I think it's worth it.

taisdesouzalessa commented 6 years ago

Just a heads up: this component probably won't be present in the V1 design of the page (it is a P2 priority). It should be in V2, though. So we have some time available for implementation. Current comp here: https://redpen.io/jv8a447745b88fc8ab

gideonthomas commented 6 years ago

Filed https://github.com/mozilla/network-pulse-api/issues/392 and it's related PR: https://github.com/mozilla/network-pulse-api/pull/393 for filtering by the presence of help types.

gideonthomas commented 6 years ago

The pulse api work for this is done (on staging). You can now hit /v2/entries/?has_help_types=True or /v2/entries/?has_help_types=False.

xmatthewx commented 6 years ago

Thanks @gideonthomas! That's great. Closing.