def _inc_dec_tag(tag_name, add=True): """ Increments or decrements the counter of a tag. """ if tag_name != None and len(tag_name) > 0: if add: debug("INC TAG USAGE: "+ tag_name) db.zincrby(POPULAR_TAGS, tag_name, 1) else: debug("DEC TAG USAGE: "+ tag_name) db.zincrby(POPULAR_TAGS, tag_name, -1) # Delete the tag from the list if it has a score of 0 #if db.zrank(POPULAR_TAGS, tag_name) == 0: if _alternative_score(tag_name) == 0: # Delete from the specifig index of tag[0] -- tags _delete_tag_index_letter_tags(tag_name) # Delete from the index of tags if the tag is the last on index num = get_tags_by_index_letter(tag_name[0]) if num != None and len(num) == 0: _delete_symbol_index(tag_name[0]) db.zrem(POPULAR_TAGS, tag_name)
def delete_post(post_id, username): """ Deletes a post (as well as its related set of tags). """ debug("DELETE POST. username:"******",post:" + str(post_id)) post_id = str(post_id) if _is_post_created(post_id): # Delete each of the tags (to decrement the score in the ranking) for temp_tag in get_post_tags(post_id): delete_tag_from_post(post_id, temp_tag) # Delete the set of tags that the post has tags_id = db.hget(post_id + APPEND_KEY_POSTS, KEY_TAGS) db.delete(tags_id + APPEND_KEY_TAG) # Delete the counter of votes that the post has votes_id = db.hget(post_id + APPEND_KEY_POSTS, KEY_VOTES) db.delete(votes_id + APPEND_KEY_VOTE) # Delete the post from the sorted set of posts by date db.zrem(username + APPEND_SEARCH_POST_TIMEDATE, post_id) # Delete the post id from the user's post list # (1 is the number of items to be removed) db.lrem(username + APPEND_KEY_POSTS, 1, post_id) # Delete the post from the last updates _delete_post_last_updates(post_id) # Delete the post from the global ranking db.zrem(POPULAR_TOP_POSTS, post_id) # Delete the hash of the post db.delete(post_id + APPEND_KEY_POSTS) """ db.hdel(post_id + APPEND_KEY_POSTS, KEY_TAGS) db.hdel(post_id + APPEND_KEY_POSTS, KEY_TITLE) db.hdel(post_id + APPEND_KEY_POSTS, KEY_DATE) db.hdel(post_id + APPEND_KEY_POSTS, KEY_CONTENTS) """ return True else: return False
def _delete_tag_index_letter_tags(tag): """ Deletes a tag from the index of tag[0] -- tags.""" db.zrem(tag[0].upper() + APPEND_KEY_INDEX_LETTER_TAG, tag)