Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mbrier/plat 000/revert subscriptions #4598

Merged
merged 3 commits into from
Jan 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -865,6 +866,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 @@ -951,6 +957,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