unfollow-fix-2
This commit is contained in:
parent
1572c77882
commit
e6cd0ecadc
|
@ -73,7 +73,6 @@ async def follow(_, info, what, slug):
|
||||||
@login_required
|
@login_required
|
||||||
async def unfollow(_, info, what, slug):
|
async def unfollow(_, info, what, slug):
|
||||||
follows = None
|
follows = None
|
||||||
error = ''
|
|
||||||
try:
|
try:
|
||||||
user_id = info.context.get('user_id')
|
user_id = info.context.get('user_id')
|
||||||
if not user_id:
|
if not user_id:
|
||||||
|
@ -81,6 +80,7 @@ async def unfollow(_, info, what, slug):
|
||||||
follower_query = select(Author).filter(Author.user == user_id)
|
follower_query = select(Author).filter(Author.user == user_id)
|
||||||
[follower] = get_with_stat(follower_query)
|
[follower] = get_with_stat(follower_query)
|
||||||
if follower:
|
if follower:
|
||||||
|
logger.info(f'@{follower.slug} unfollowing')
|
||||||
if what == 'AUTHOR':
|
if what == 'AUTHOR':
|
||||||
if author_unfollow(follower.id, slug):
|
if author_unfollow(follower.id, slug):
|
||||||
author_query = select(Author).where(Author.slug == slug)
|
author_query = select(Author).where(Author.slug == slug)
|
||||||
|
@ -105,12 +105,11 @@ async def unfollow(_, info, what, slug):
|
||||||
community_unfollow(follower.id, slug)
|
community_unfollow(follower.id, slug)
|
||||||
elif what == 'REACTIONS':
|
elif what == 'REACTIONS':
|
||||||
reactions_unfollow(follower.id, slug)
|
reactions_unfollow(follower.id, slug)
|
||||||
|
return {'error': "", f'{what.lower()}s': follows}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error = e
|
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
finally:
|
return {'error': str(e), f'{what.lower()}s': follows}
|
||||||
return {'error': str(error), f'{what.lower()}s': follows}
|
|
||||||
|
|
||||||
|
|
||||||
async def get_follows_by_user_id(user_id: str):
|
async def get_follows_by_user_id(user_id: str):
|
||||||
|
|
|
@ -58,9 +58,11 @@ async def set_follows_authors_cache(follows, author_id: int):
|
||||||
async def update_follows_for_author(
|
async def update_follows_for_author(
|
||||||
follower: Author, entity_type: str, entity: dict, is_insert: bool
|
follower: Author, entity_type: str, entity: dict, is_insert: bool
|
||||||
):
|
):
|
||||||
|
follows = []
|
||||||
redis_key = f'author:{follower.id}:follows-{entity_type}s'
|
redis_key = f'author:{follower.id}:follows-{entity_type}s'
|
||||||
follows_str = await redis.execute('GET', redis_key)
|
follows_str = await redis.execute('GET', redis_key)
|
||||||
follows = json.loads(follows_str) if follows_str else []
|
if isinstance(follows_str, str):
|
||||||
|
follows = json.loads(follows_str)
|
||||||
if is_insert:
|
if is_insert:
|
||||||
follows.append(entity)
|
follows.append(entity)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user