Skip to content

Instantly share code, notes, and snippets.

@p
Created November 2, 2012 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p/ce153a7c7acb9b77300a to your computer and use it in GitHub Desktop.
Save p/ce153a7c7acb9b77300a to your computer and use it in GitHub Desktop.
1. get rows with topic_id=old topic, note user ids
2. get rows with topic_id=new topic, note user ids
3. obtain user ids for which there are rows with old topic id and no new topic id
4. update giving topic_id=old topic and user_id in set to topic_id=new topic
5. delete rows with topic_id=old topic
notify status is:
1 for spam
0 for already spammed, don't spam
1 + 0 = 1 (avoid missing updates for possibly the important one of the merged topics)
therefore:
1. get rows with topic_id=old topic, create user id to notify status map
2. get rows with topic_id=new topic, create user id to notify status map
* could restrict on user_id from the map in #1 but query will grow larger and possibly too large
For rows where notify status in old topic is 0:
3. obtain user ids for which there are rows with old topic id and no new topic id
(present in map #1 and absent in map #2)
4. update giving topic_id=old topic and user_id in set to topic_id=new topic
5. delete rows with topic_id=old topic
For rows where notify status in old topic is 1:
3. same as above
4. same as above but also set notify_status=1 for all changed rows
5. for all rows (user ids) that were not updated in #3/#5,
update rows with user_id in set and topic_id=new topic and set notify_status=1
6. delete rows with topic_id=old topic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment