Getting badges twice
-
I'll just put that here and page @PJH
A few minutes I got a 2^x-badge again.
I also can't upload an image here, so take this Dropbox-Link instead (Gives me a non descriptive error-message)
https://www.dropbox.com/s/8etrve1ti5jl0c5/Screenshot 2014-10-18 16.56.58.png?dl=0
Welp, at least one boxing does it's job.
Filed Under: Sigh
-
This topic was automatically closed after 61 minutes. New replies are no longer allowed.
-
-
Only one listed on your badges page though...
-
What if 512 posts were made, then one got deleted, then another was made?
-
While this is a potential edge-case, I don't think this is what happened in my case. I rarely make posts that get deleted.
Filed Under: Because I am a boring poster :D
-
discoursistency!
-
Maybe one of them got ineligible? Moved into a non-eligible category, 4-post topic where one of the other topics got deleted, etc...
-
I assume the badges_users table doesn't have a unique constraint. I wonder if this can be abused.
-
It may not be the badge that pops up twice, but the notification.
-
Maybe one of them got ineligible? Moved into a non-eligible category, 4-post topic where one of the other topics got deleted, etc...
Unlikely, as pointed out. I've not added any topics to the exclusions list recently either. The revocation only gets run once a day anyway.
I assume the badges_users table doesn't have a unique constraint. I wonder if this can be abused.
discourse=# \d user_badges; Table "public.user_badges" Column | Type | Modifiers -----------------+-----------------------------+---------------------------------------------------------- id | integer | not null default nextval('user_badges_id_seq'::regclass) badge_id | integer | not null user_id | integer | not null granted_at | timestamp without time zone | not null granted_by_id | integer | not null post_id | integer | notification_id | integer | seq | integer | not null default 0 Indexes: "user_badges_pkey" PRIMARY KEY, btree (id) "index_user_badges_on_badge_id_and_user_id_and_post_id" UNIQUE, btree (badge_id, user_id, post_id) WHERE post_id IS NOT NULL "index_user_badges_on_badge_id_and_user_id_and_seq" UNIQUE, btree (badge_id, user_id, seq) WHERE post_id IS NULL "index_user_badges_on_badge_id_and_user_id" btree (badge_id, user_id)
-
Yes, it's only unique for badge, user, post and bage, user, seq.
Wtf is seq?
-
I'm assuming related to sequence of badges? Display order maybe?
-
i think it's order of badge granting.... there are badges that get awarded multiple times (i have over 600 "nice Post"'s now)
-
A quick rummage through the code indicates it's the nth badge of those that can be multiply assigned. Per user. The next one worked out using, basically,
select max(seq)+1 where user_id=whoever
if user_badge.nil? || (@badge.multiple_grant? && @post_id.nil?) UserBadge.transaction do seq = 0 if @badge.multiple_grant? seq = UserBadge.where(badge: @badge, user: @user).maximum(:seq) seq = (seq || -1) + 1 end user_badge = UserBadge.create!(badge: @badge, user: @user, granted_by: @granted_by, granted_at: Time.now, post_id: @post_id, seq: seq)
-
More:
[pjh@sofa discourse]$ grep seq ./db/migrate/20140809224243_add_user_badge_unique_index.rb -B10 -A10 --color class AddUserBadgeUniqueIndex < ActiveRecord::Migration def up # used to keep badges distinct add_column :user_badges, :seq, :integer, default: 0, null: false # invent artificial seq for badges execute " UPDATE user_badges ub1 SET seq = X.seq FROM ( SELECT ub.id, rank() OVER (PARTITION BY user_id ORDER BY granted_at) seq FROM user_badges ub JOIN badges b ON b.id = ub.badge_id WHERE b.multiple_grant ) X WHERE ub1.id = X.id "
-
-
i think it's order of badge granting.... there are badges that get awarded multiple times (i have over 600 "nice Post"'s now)
I seem to have 2343 of those. I would trade them in for a pendantry one if that's a thing.
-
So instead of just assuming that the id column which is the main table row sequence that will always be in order, they create another column to be sure postgre doesn't break down and you know start assigning duplicate ids like discsource?
-
-
I actually already wear a pendant, in silver not gold. A badge to match would be kind of awesome.
-
i'd practically demand one.
i don't wear pendants because .... well i don't own any. no one's given me one yet.
i do wear lapel pins regularly. if you look in the pictures of my office pace you can see them. i stick them into my cue wall when i'm not wearing them.
-
i don't wear pendants because .... well i don't own any. no one's given me one yet.
Here, have a particularly WTFy one:
-
I have flat out asked for a pendantry badge, not to mention pimped out for one, I'm just not pendantic enough
As for wearing a pendant, this is actually the third necklace of this kind, the first two I bought and gave away to people, the third one was bought for me years and years ago.