Topic Ratings Plugin

No, problem at all! As long as things are kept consistent across updates :slight_smile:
Thank you for all your hard work!

1 Like

Hey @angus,

I want to extend this to allow for multiple ratings instead of just one.
e.g. in my case Train reviews can include punctuality, cleanliness, food.

I’ve cloned the repo and exploring the code, a few pointers will be very helpful.

1 Like

Do you mean multiple ratings on one topic? Yes that could be done I suppose. Basically, you’ll need to add in additional custom fields, wherever the current rating custom fields are. And some conditional logic to handle the calculation of the average separately for each type.

For example, you may end up with something like this for saving the rating when a post is created:

  DiscourseEvent.on(:post_created) do |post, opts, user|
    if opts[:rating] || opts[:rating_type2]
      post.custom_fields['rating'] = opts[:rating] if opts[:rating]
      post.custom_fields['rating_type2'] = opts[:rating_type2] if opts[:rating_type2]
      post.custom_fields["rating_weight"] = 1
      post.save_custom_fields(true)
      RatingsHelper.handle_rating_update(post, opts)
    end
    ///

Then add some conditional logic in handle_rating_update to calculate averages and push those averages to the topic, for each type of rating.

The newest version makes opening the rating topic too slow. for example if other topics would open in two seconds, rating topic opens in 5 seconds.

on the other hand is there an option to remove stars from below topic title and just let them be inside the topic?

Can you give me an example of this? In my own testing on localhost, and on https://discourse.angusmcleod.com.au, rating topics load at the same speed as any other topic.

I’ve added settings for the average ratings in the topic and in the topic list:

https://github.com/angusmcleod/discourse-ratings/commit/c1ada78cbd12d6422b3fefa1faae2022c4447f04

1 Like

here is all our rating topics.

you can open this one since it is the most rated topic.

The slow load of that topic may have more to do with it having 4542 posts :slight_smile: That’s a very long topic.

Nevertheless, I’ve made some performance improvements. The first time you load the topic you won’t notice a difference, but subsequent loads may be faster, if the ratings plugin is having any effect on the load time.

https://github.com/angusmcleod/discourse-ratings/commit/55dd33988d3fd9b7b4368d7618d19481176de13f

Let me know how it goes.

3 Likes

but as I told previously, it was ok until some days ago I updated both discourse and this plugin to the latest version.

I updated the plugin, but unfortunately it didn’t have any effect imo. What is it that takes the most process in this plugin?

If it is calculating the average rating, maybe you could cache the value for, lets say, one day perhaps?

It could be a disaster for rating topics like mine that rapidly grows in number of posts.

However again I need to say that this problem occurred very recently in my last update (discourse core + all plugin). So maybe its because of one of your new commits, or even commits to the core discourse that caused the problem?

Aside from the changes I just made, none of my commits in the last few months to this plugin would have had an effect on performance. They were style and translation changes.

So if there has been a noticeable deterioration in performance in those very large topics in the last few days, it is probably something core related.

I can take a look in more detail at what might have caused this in core Discourse later this week, but you should raise this with the Discourse team.

*edit @parisa You may want to have a read of this topic: Performance improvements on long topics?. Another host with a topic of a similar size (i.e. 4.5K posts) has the same issue:

Yes you are right. I think I found the problem. Its the new mixed text direction feature.

2 Likes

Quick question: To rate a topic do you need to post in it - or can you rate without making a reply to the topic?

Im asking as I would like to add a book review section to my site. Im not sure what is best: being able to add star rating with or without adding a reply/reason… :thinking:

Now I have installed this great plugin.

I have a question to the styling

  1. “No ratings yet”
    I would like that if it is rated then show the stars. If not, show nothing. I dont want a list of “No ratings yet”, is that possible?

  2. Could “7” and “17” in the blue circle is normally placed after the title. Is that possible?

1 Like

Maybe instead of not showing “no ratings yet” it would be better to show a type of “be the first to rate”?

4 Likes

I will take at look at both issues tomorrow.

2 Likes

Else show the icon for no stars yet (5 empty stars).

The mix of text and grafic is not eye candy, I think :smiley:

I’ve removed the ‘No ratings yet’ label from the topic list. As you allude, it’s not really necessary there. That also fixes the unread count alignment

https://github.com/angusmcleod/discourse-ratings/commit/f25c9f38be6d4184268d49d24ac9069dd7af6603

It’s still in the topic itself.

You can edit the text itself by editing the translation files in Admin > Customize > Text Content. Search for “no_ratings”.

3 Likes

Much better :smiley:

Before

Now

But there is still a line break from title to “unread posts” - the blue circle

This is the look in a category where you havent enable ratings

But much better :+1:

Any plans to solve this?

Apologies, this got left off my list. Now fixed:

https://github.com/angusmcleod/discourse-ratings/commit/3827b080089d26ecd30d514430ae1ff857e715ba

3 Likes