Permalink
Browse files

Changed from url based ID to a HashIDS based one in the modify() func…

…tion.
  • Loading branch information...
geekgirlbeta committed Sep 2, 2017
1 parent 0a7a93b commit aaa8427083adf075dd5138969b6397496c7e1ad5
Showing with 9 additions and 12 deletions.
  1. +9 −12 edit.py
21 edit.py
@@ -135,6 +135,8 @@ def modify(self, raw_id, page_title=None, desc_text=None, url_address=None, auth
"""Modify an existing link in the database."""
# TODO: REFACTOR THIS LIKE WOAH
url_to_be_modified = self.connection.hmget(self.prefix_key(raw_id), "url_address")[0]
fields = {}
if page_title is not None:
@@ -164,9 +166,8 @@ def modify(self, raw_id, page_title=None, desc_text=None, url_address=None, auth
if fields:
if fields.get("url_address", None):
comp_id, junk = self.key(url_address)
if comp_id != raw_id:
raw_id = self.rename(raw_id, url_address)
if self.url_exists(url_address):
raise Exception("URL '%s' exists" % (url_address,))
# TODO: consider doing this in the pipeline and putting a watch on the
# link's key in case it changes during processing.
@@ -181,6 +182,11 @@ def modify(self, raw_id, page_title=None, desc_text=None, url_address=None, auth
with self.connection.pipeline() as pipe:
pipe.hmset(self.prefix_key(raw_id), fields)
if fields.get("url_address", None):
if url_to_be_modified != fields["url_address"]:
pipe.srem("url_hold", url_to_be_modified)
pipe.sadd("url_hold", fields["url_address"])
if fields.get("tags", None):
for existing_tag in old_tags:
tag_key = 'tag:%s' % (existing_tag,)
@@ -304,15 +310,6 @@ def url_exists(self, url_address):
else:
return False
# def url_changed(self, raw_id, url_address):
# """
# Returns True if the provided url is different than the one used to generate the raw_id
# """
# comp_id, junk = self.key(url_address)
# if comp_id == raw_id:
# return False
# else:
# return True
class ReadingListManager:
"""

0 comments on commit aaa8427

Please sign in to comment.