Discourse Gamification

Is it possible to somehow manually reset or rewrite the Leaderboard URL? In our case we tested some leaderbaords, deleted them later.

E.g. /leaderboards/5 to /leaderboards/1.

Is it possible to award points to a user as an extra reward? :grin:

1 Like

You may want to see:

which has this curl request inside:

curl --location 'https://my.discourse.com/admin/plugins/gamification/score_events' \
--header 'Api-Key: <your key>' \
--header 'Api-Username: <your username>' \
--header 'Content-Type: application/json' \
--data '{
    "user_id": "101",
    "date": "2024-05-15",
    "points": "-141",
    "description": "Gamification point adjustment"
}'
2 Likes

I enabled this plugin in admin, but the leaderboard tab did not automatically appear. I also added new leaderboards, but they did not show up. Why is this happening? Where should I look for these leaderboards?

I think you have to add them to the sidebar yourself :thinking:. The leaderboards are at /leaderboard, /leaderboard/2, /leaderboard/3 etc.

Is it possible to create a leaderboard for a specific category or tag?

Leaderboards are tied to groups. But you can specify which categories affect all the leaderboards in the gamification settings. Seems like an interesting idea to move that to the leaderboard, to for example have a Support leaderboard here in this community.

3 Likes

2 posts were split to a new topic: Reducing points for flagged users

Is there a way for me to exclude myself from the rankings?

yes add yourself to a new group (call it ‘leaderboard-exclusion’ or something) and then exclude the group in the plugin settings.

edit: this will also easily allow you to exclude anyone else if you so wish at some point, by adding them to the same group. :slight_smile:

3 Likes

Thank you so much. That makes sense.

2 Likes

After I upgraded to version 2026.1.0, I created a monthly leaderboard, and then accessing the following route caused an error:

http://localhost:4200/admin/plugins/discourse-gamification/leaderboards

The error is as follows:

assert.js:40 
 Uncaught (in promise) Error: Assertion Failed: You attempted to update `_value` on `TrackedStorageImpl`, but it had already been used previously in the same computation.  Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.

`_value` was first used:

- While rendering:
  {{outlet}} for -top-level
    -top-level
      {{outlet}} for application
        application
          DiscourseRoot
            {{outlet}} for admin
              admin
                {{outlet}} for adminPlugins
                  admin-plugins
                    {{outlet}} for adminPlugins.show
                      show
                        AdminPluginConfigPage
                          AdminPluginConfigArea
                            {{outlet}} for adminPlugins.show.discourse-gamification-leaderboards
                              adminPlugins.show.discourse-gamification-leaderboards
                                {{outlet}} for adminPlugins.show.discourse-gamification-leaderboards.index
                                  discourse-gamification-leaderboards
                                    DPageSubheader
                                      (result of a `unknown` helper)

Stack trace for the update:
    at TrackedArray._dirtyCollection2 (array.ts:163:13)
    at Object.set (array.ts:126:15)
    at Proxy.sort (<anonymous>)
    at AdminPluginsShowDiscourseGamificationLeaderboardsIndexController.sortedLeaderboards (index.js:23:1)
    at AdminPluginsShowDiscourseGamificationLeaderboardsIndexController.<anonymous> (handle-descriptor.js:67:17)

I located the problematic file as follows:

plugins/discourse-gamification/admin/assets/javascripts/discourse/controllers/admin-plugins/show/discourse-gamification-leaderboards/index.js

Specific code:

  @discourseComputed("model.leaderboards.@each.updatedAt")
  sortedLeaderboards(leaderboards) {
    return (
      leaderboards?.sort((a, b) => compare(b?.updatedAt, a?.updatedAt)) || [] // line 22
    );
  }

The reason for the error is:

Ember.js (or more accurately, the Glimmer tracking system) assertion error in reactive state management. The core reason is: within the same computation cycle, you first read a tracked (tracked state) value, and then attempt to modify that value. This “use then update” operation can lead to logical confusion, infinite loops, or performance issues, so Ember directly prohibits this behavior.

Key issue:

  • Array.sort() modifies the original array in place, which updates the @tracked leaderboards state.

  • The responsibility of a computed property (sortedLeaderboards) is to derive a new value, not to modify the original state; it should itself be a “pure function” (no side effects, does not modify the input source).

Here is the fix:

  @discourseComputed("model.leaderboards.@each.updatedAt")
  sortedLeaderboards(leaderboards) {
    return (
      //leaderboards?.sort((a, b) => compare(b?.updatedAt, a?.updatedAt)) || []
      leaderboards?.slice().sort((a, b) => compare(b?.updatedAt, a?.updatedAt)) || []
    );
  }

Screenshot after fixing:

And this kind of similar issue doesn’t seem to be an isolated case. I suspect it’s an incompatibility issue caused by the emberjs upgrade. However, many places in plugins haven’t been modified to keep up with the upgrade, as this work is not as simple as it sounds.

Question: Is there a delay as to when points are awarded. For example, new users are doing point paying things, like posting a new topic or giving a like, but their scores don’t show up. I have trust level 0 included in the settings, so I am assuming it’s just a delay in assigning points? If so, how often does it calculate and update? Thank you!

4 Likes