# Gamification and invitations

**URL:** <https://meta.discourse.org/t/gamification-and-invitations/269544>\
**Category:** Bug\
**Tags:** gamification, invites\
**Created:** [June 25, 2023, 10:47am UTC](https://meta.discourse.org/t/gamification-and-invitations/269544 "2023-06-25T10:47:31Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [September 25, 2023, 8:35am UTC](https://meta.discourse.org/t/gamification-and-invitations/269544/4 "2023-09-25T08:35:32Z")

</div>

That would be a good approach, except for one thing:

> [@JammyDodger](#):
>
> `AND u.created_at > iu.redeemed_at` would also exclude inviting existing users.

This does not work well. Sometimes the user is created slightly before the redemption took place. No idea why. Mostly _tenths_ of seconds, but I found a few of _tens_ of seconds as well.

Tested on a real database.

```plaintext
select 
  iu.redeemed_at iu_AS redeemed_at, 
  u.created_at AS u_created_at, 
  u.created_at > iu.redeemed_at AS u_created_gt_iu_redeemed 
from invited_users iu 
left join users u on u.id = iu.user_id 
where iu.redeemed_at is not null
order by iu.id desc;

```

```plaintext
       iu_redeemed_at | u_created_at | u_created_gt_iu_redeemed 
----------------------------+----------------------------+--------------------------
 2023-09-08 00:00:47.557057 | 2023-09-08 00:00:48.376446 | t
 2023-08-25 20:09:03.486362 | 2023-08-25 20:09:03.201357 | f
 2023-08-15 23:38:32.271709 | 2023-08-15 23:38:33.570299 | t
 2023-08-14 10:44:34.19912 | 2023-08-14 10:44:35.429371 | t
 2023-08-12 13:41:10.428013 | 2023-08-12 13:41:11.733973 | t
 2023-07-31 17:58:13.511289 | 2023-07-31 17:57:50.427111 | f
 2023-07-23 00:56:33.455185 | 2023-07-23 00:55:47.999263 | f
 2023-07-19 08:42:44.908096 | 2023-07-19 08:42:46.040201 | t
 2023-06-30 09:11:38.829692 | 2023-06-30 09:11:39.618586 | t
 2023-06-30 08:37:02.322192 | 2023-06-30 08:37:03.133769 | t
 2023-06-29 16:24:01.705616 | 2023-06-29 16:24:02.55067 | t
 2023-06-29 12:53:33.245688 | 2023-06-29 12:53:34.067159 | t

```

---

_[View the full topic](https://meta.discourse.org/t/gamification-and-invitations/269544)._
