mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-15 21:31:26 +00:00
clean up List db queries
- don't unnecessarily query DB in List views - use more efficient query in remove_from_group List class method
This commit is contained in:
parent
5d7f77021b
commit
41f27a4a66
2 changed files with 3 additions and 8 deletions
|
@ -101,15 +101,10 @@ class List(OrderedCollectionMixin, BookWyrmModel):
|
|||
def remove_from_group(cls, owner, user):
|
||||
"""remove a list from a group"""
|
||||
|
||||
memberships = GroupMember.objects.filter(group__user=owner, user=user).all()
|
||||
|
||||
for membership in memberships:
|
||||
# remove this user's group-curated lists from the group
|
||||
cls.objects.filter(group=membership.group, user=membership.user).update(
|
||||
cls.objects.filter(group__user=owner, user=user).all().update(
|
||||
group=None, curation="closed"
|
||||
)
|
||||
|
||||
|
||||
class ListItem(CollectionItemMixin, BookWyrmModel):
|
||||
"""ok"""
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ class Lists(View):
|
|||
book_list = form.save()
|
||||
# list should not have a group if it is not group curated
|
||||
if not book_list.curation == "group":
|
||||
models.List.objects.filter(id=book_list.id).update(group=None)
|
||||
book_list.update(group=None)
|
||||
|
||||
return redirect(book_list.local_path)
|
||||
|
||||
|
@ -193,7 +193,7 @@ class List(View):
|
|||
return redirect("list", book_list.id)
|
||||
book_list = form.save()
|
||||
if not book_list.curation == "group":
|
||||
models.List.objects.filter(id=book_list.id).update(group=None)
|
||||
book_list.update(group=None)
|
||||
return redirect(book_list.local_path)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue