Any packages for Likes/Star Counting?

Does anybody have a package or pattern for good, scalable “Likes” or “Stars” counting (like on GitHub)? It’s not an entirely trivial problem, so I don’t want to reinvent the while if somebody has already written a solid, pure Elixir package for this. I did some searching but couldn’t find anything on Google or GitHub.

Any recommendations?

If you’re looking for techniques/utilities to crawl the pages of GitHub, or the like, I don’t have any immediate recommendations. Googling for “GitHub crawler” or looking for List API endpoints, e.g. Users - GitHub Docs (e.g. getting all users, then fanning out to their repos), may be entrypoints.

To just retrieve the stars or other data about a given repository, GitHub’s API is probably your best friend. Repositories - GitHub Docs provides a number of fields including stargazers_count and watchers_count.
For Elixir, from a Google search, I see this repo GitHub - edgurgel/tentacat: Simple Elixir wrapper for the GitHub API (I haven’t used/endorsed). But if you just need a select number of endpoints, using something like GitHub - elixir-tesla/tesla: The flexible HTTP client library for Elixir, with support for middleware and multiple adapters. may be useful too.

No no no, sorry, I mean to implement a system similar to github stars. As in, you’ve got your Things table, you’ve got your User table, you’ve got your UserLikesThing table. The naive implementation is pretty simple, but can get ugly when counting really really popular things, getting summary statistics, etc. I was wondering if there was a “Likes” package which solved the common hiccups, maybe with a GenServer/cache already.

1 Like

I don’t have an answer, but I have questions for the OP.

  1. Do you have any reference materials (technical blog posts, papers, etc.) that can help us understand the implementation pitfalls you’re referring to for the naive implementation & how they can be addressed? It’d be nice for anyone who comes across this and doesn’t have familiarity with the problem space to be able to contextualize the issue.
  2. Are there any reference implementations in other languages that you could point to that address this? Being able to hear a “like package X in Ruby/Python/etc.” could spark recognition if an Elixir library does exist, and if one doesn’t exist, knowing what a reference implementation does could lead to either developing an idiomatic approach as a library or presenting a pattern where Elixir/OTP magic makes the implementation trivial enough to not need a library.

Looking forward to having some resources I could use to expand my own understanding if you’re able to provide them, so thanks in advance for indulging my request.

I haven’t ran this myself, but I remember GitHub - redrabbit/ A Git source code management tool powered by Elixir with easy installation & high extensibility. getting quite a bit of traction a while back. It doesn’t look like it has stars but maybe the base modes are re-usable.

Here’s an example in Django/Pinax: GitHub - pinax/pinax-likes: a liking app for Django

Their solution is simple though, pretty much what I described above, and to be honest I think I’m overthinking this problem - I’m not at the scale where it matters. I’ll just do it with a simple little table. Thanks for your time!


Sorry, my mistake!
Along with the Django example, this ER diagram looks like it may be useful for the schema impl: mysql - Implementing Comments and Likes in database - Stack Overflow.
Kind of what I’d expect for something like that. Having user+likes as one N:N table referencing users and the entity. That way you can track what a user has like as well as sum up the total likes for an entity. Don’t even need all the inheritance stuff if you’re just liking one thing.
Something like this would probable “scale” well enough in a RDBMS like postgres for some time.

1 Like