async def handle_refresh_my_track_likes(p): likes = db.func.count(TrackLike.track_id) track_likes_query = db.select([PenguinTrack.id, likes])\ .select_from(PenguinTrack.outerjoin(TrackLike))\ .where(PenguinTrack.owner_id == p.data.id)\ .group_by(PenguinTrack.id).gino.load(PenguinTrack.load(likes=ColumnLoader(likes))) async with db.transaction(): async for track in track_likes_query.iterate(): await p.send_xt('getlikecountfortrack', p.data.id, track.id, track.likes)
async def get_tracks(self): self.playlist = [] likes = db.func.count(TrackLike.track_id) tracks_query = db.select([PenguinTrack, likes]) \ .select_from(PenguinTrack.outerjoin(TrackLike)) \ .where((PenguinTrack.owner_id.in_(tuple(self.room.penguins_by_id.keys()))) & (PenguinTrack.sharing == True)) \ .group_by(PenguinTrack.id).gino.load(PenguinTrack.load(likes=ColumnLoader(likes))) async with db.transaction(): async for track in tracks_query.iterate(): self.playlist.append(track)
async def get_player_tracks(p): player_tracks = [] likes = db.func.count(TrackLike.track_id) tracks_query = db.select([PenguinTrack, likes])\ .select_from(PenguinTrack.outerjoin(TrackLike))\ .where(PenguinTrack.owner_id == p.data.id)\ .group_by(PenguinTrack.id).gino.load(PenguinTrack.load(likes=ColumnLoader(likes))) async with db.transaction(): async for track in tracks_query.iterate(): player_tracks.append(f'{track.id}|{track.name}|{int(track.sharing)}|{track.likes}') return player_tracks
async def get_shared_tracks(p): shared_tracks = [] likes = db.func.count(TrackLike.track_id) tracks_query = db.select([PenguinTrack, likes])\ .select_from(PenguinTrack.outerjoin(TrackLike))\ .where((PenguinTrack.owner_id.in_(tuple(p.server.penguins_by_id.keys())) & (PenguinTrack.sharing == True)))\ .group_by(PenguinTrack.id).gino.load(PenguinTrack.load(likes=ColumnLoader(likes))) async with db.transaction(): async for track in tracks_query.iterate(): penguin = p.server.penguins_by_id[track.owner_id] shared_tracks.append(f'{penguin.data.id}|{penguin.data.nickname}|{track.id}|{track.likes}') return shared_tracks
async def get_tracks(self): self.playlist = [] self.penguins_by_track_id = {} room = self.server.rooms[SoundStudio.StudioRoomId] room_penguins = room.penguins_by_id.copy() likes = db.func.count(TrackLike.track_id) tracks_query = db.select([PenguinTrack, likes]) \ .select_from(PenguinTrack.outerjoin(TrackLike)) \ .where((PenguinTrack.owner_id.in_(tuple(room_penguins.keys()))) & (PenguinTrack.sharing == True)) \ .group_by(PenguinTrack.id).gino.load(PenguinTrack.load(likes=ColumnLoader(likes))) async with db.transaction(): async for track in tracks_query.iterate(): self.playlist.append(track) self.penguins_by_track_id[track.id] = room_penguins[ track.owner_id]