Skip to content

Commit

Permalink
Mbrier/plat 000/revert subscriptions (#4598)
Browse files Browse the repository at this point in the history
Co-authored-by: Michelle Brier <michelle.brier4@gmail.com>
  • Loading branch information
stereosteve and michellebrier authored Jan 12, 2023
1 parent 2e82719 commit 920cb5e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions discovery-provider/src/tasks/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from src.models.social.follow import Follow
from src.models.social.repost import Repost
from src.models.social.save import Save
from src.models.social.subscription import Subscription
from src.models.tracks.track import Track
from src.models.tracks.track_route import TrackRoute
from src.models.users.associated_wallet import AssociatedWallet
Expand Down Expand Up @@ -820,6 +821,11 @@ def revert_blocks(self, db, revert_blocks_list):
revert_follow_entries = (
session.query(Follow).filter(Follow.blockhash == revert_hash).all()
)
revert_subscription_entries = (
session.query(Subscription)
.filter(Subscription.blockhash == revert_hash)
.all()
)
revert_playlist_entries = (
session.query(Playlist).filter(Playlist.blockhash == revert_hash).all()
)
Expand Down Expand Up @@ -906,6 +912,23 @@ def revert_blocks(self, db, revert_blocks_list):
logger.info(f"Reverting follow: {follow_to_revert}")
session.delete(follow_to_revert)

for subscription_to_revert in revert_subscription_entries:
previous_subscription_entry = (
session.query(Subscription)
.filter(
Subscription.subscriber_id
== subscription_to_revert.subscriber_id
)
.filter(Subscription.user_id == subscription_to_revert.user_id)
.filter(Subscription.blocknumber < revert_block_number)
.order_by(Subscription.blocknumber.desc())
.first()
)
if previous_subscription_entry:
previous_subscription_entry.is_current = True
logger.info(f"Reverting subscription: {subscription_to_revert}")
session.delete(subscription_to_revert)

for playlist_to_revert in revert_playlist_entries:
playlist_id = playlist_to_revert.playlist_id
previous_playlist_entry = (
Expand Down

0 comments on commit 920cb5e

Please sign in to comment.