|
| 1 | +# Inactive user cleanup |
| 2 | +When user registration finishes and users not passing "activation", corresponding DB record stays for ttl. |
| 3 | +But all metadata/alias/email records stay forever. |
| 4 | + |
| 5 | +1. Add additional Redis HASH and ZSET handling inactive users list. |
| 6 | +2. Change registration action: |
| 7 | + - remove ttl assignment from from `USER_DATA` key |
| 8 | + - call inactive list append process `addInactiveUser` |
| 9 | +3. Change activation action: |
| 10 | + - add inactive list cleanup `deleteInactiveUser` |
| 11 | +4. Add interval task. |
| 12 | +5. Add config parameter |
| 13 | +6. Move 'delete user' transaction function into separate file from `actions/remove.js` to `utils/removeUser.js` |
| 14 | + |
| 15 | +## Config changes |
| 16 | +Added new `deleteInactiveAccountsInterval` seconds to run cleaner task. |
| 17 | + |
| 18 | +## Constants |
| 19 | +New constants `USERS_ACTIVATE` - ZSET handling userId regtime, `USERS_ACTIVATE_AUDIENCE` - userId to audience binding |
| 20 | + |
| 21 | +## utils/inactiveUsers.js |
| 22 | +Handles all logic, including task creator, and database actions for InactiveUsersList |
| 23 | + |
| 24 | +### addInactiveUser(id, audience) |
| 25 | +Adds corresponding id record into `USERS_ACTIVATE` with score eq current time. Sets `USERS_ACTIVATE_AUDIENCE` hash to track audieces provided in registration process |
| 26 | + |
| 27 | +### deleteInactiveUser(id) |
| 28 | +Removes id dependent data from `USERS_ACTIVATE`, `USERS_ACTIVATE_AUDIENCE` |
| 29 | + |
| 30 | +### cleanInactiveUsers() |
| 31 | +Gets outdated users from `USERS_ACTIVATE` and deletes all user data from database(same as `@ms-users-api.remove`) |
| 32 | + |
| 33 | + |
| 34 | +#### Possible variant |
| 35 | +- Create additional set with id's of inactive users (`users-activate`). |
| 36 | + * Change activation process: remove successfully activated user id from `users-activate`. |
| 37 | + * Change registration process: insert inactive user id into `users-activate`. |
| 38 | +- Add repeating task with interval `config.incativeCleanupInterval`. |
| 39 | + * Sets `dlock` for cleanup operation |
| 40 | + * Gets list from `user-activate` |
| 41 | + * Delete all corresponding data from DB for this user id's: |
| 42 | + all keys `{id}!metadata!{audience}`, and keys from hashes: `USERS_USERNAME_TO_ID`,`USERS_ALIAS_TO_ID`. |
| 43 | + |
| 44 | + _NOTE_: |
| 45 | + User already can be assigned to some organization. So we'll check organisation members key (`redisKey(organizationId, ORGANIZATIONS_MEMBERS)`), organisation member key (`redisKey(organizationId, ORGANIZATIONS_MEMBERS, member.email)`) and redisKey(member.email, USERS_ORGANIZATIONS); |
0 commit comments