sydevs / WeMeditate

International website promoting the practice of meditation, with online resources and free local classes.
https://www.wemeditate.com
5 stars 6 forks source link

Revise visibility on inspiration index and featured articles in header #138

Closed Ardnived closed 2 years ago

Ardnived commented 2 years ago

Questions about the events category What about the "Events" category? Those articles are timely and should possibly be unpublished or demoted after a certain amount of time. Is this category relevant enough for continued usage? Should we be soliciting yogis to promote their events via We Meditate more frequently? Can we get someone to take on the responsibility of working with yogis to set up event pages. We've had plenty of requests to promote events on We Meditate, but haven't had the bandwidth to really follow up with them.

Ardnived commented 2 years ago

For now the event category will be removed, in the future we could have a person dedicated to event promotion and liasing.

Ardnived commented 2 years ago

This is now done and in master. Needs to be tested and released. Waiting for Heroku to resolve their GitHub connection.

Ardnived commented 2 years ago

@dbackeus Are you familiar with creating Postgres queries in Rails? I'm trying to create a custom order which will put recently published articles (in the last 2 weeks) at the beginning of the list, and then randomise the order of the rest of the article. This is what I have at the moment, but it just randomises everything. scope :index_order, -> { order("CASE WHEN article_translations.published_at >= CURRENT_TIMESTAMP - INTERVAL '14 days' THEN article_translations.published_at ELSE '#{100.years.ago}' END, RANDOM()") }

If I invert the >= to a <, then everything appears in the published order. So clearly the check works to some extent (ie. when everything is ordered by 100.years.ago then randomisation kicks in). But it doesn't seem to actually pick up recent articles and put them in the right category.

Do you have any thoughts or advice?

dbackeus commented 2 years ago

I've never used RANDOM ordering. It's generally a performance issues since it requires Postgres to load an entire table into memory and then randomize. For small tables it'll be fast enough but won't scale to large tables. Presumably Wemeditate data will remain small enough for this not to become a problem though.

I'd probably make two queries for this. First (pseudo code) recent_articles = Article.where(published_at: 2.weeks.ago..).order(published_at: :desc).limit(MAX_ARTICLES) then random_articles = Article.where.not(id: recent_articles.map(&:id)).order("RANDOM()")).limit(MAX_ARTICLES - recent_articles.length).

This could be done as a single request to Postgres by using sub-queries as well but I don't think that would be helpful in the context of a Rails application.

One thing to keep in mind with regards to randomization is that if we go ahead and implement HTML caching the random order would remain the same for any given page while cached, which should be fine, but just something to keep in mind.

Ardnived commented 2 years ago

You're right, it was a simple solution with 2 queries.

The caching is fine. Already with rails caching the randomisation gets cached for a minute or two. As long as occasionally when people visit they see something different, it will help to give the illusion of freshness a bit.