backend bulk delete filter
This commit is contained in:
parent
8d9cb9261e
commit
a0f40d9970
|
|
@ -53,6 +53,10 @@ class DownloadListQueueDeleteQuerySerializer(serializers.Serializer):
|
|||
"""serialize bulk delete download queue query string"""
|
||||
|
||||
filter = serializers.ChoiceField(choices=["pending", "ignore"])
|
||||
channel = serializers.CharField(required=False, help_text="channel ID")
|
||||
vid_type = serializers.ChoiceField(
|
||||
choices=VideoTypeEnum.values_known(), required=False
|
||||
)
|
||||
|
||||
|
||||
class AddDownloadItemSerializer(serializers.Serializer):
|
||||
|
|
|
|||
|
|
@ -100,9 +100,17 @@ class PendingInteract:
|
|||
path = f"ta_download/_doc/{self.youtube_id}"
|
||||
_, _ = ElasticWrap(path).delete(refresh=True)
|
||||
|
||||
def delete_by_status(self):
|
||||
def delete_bulk(self, channel_id: str | None, vid_type: str | None):
|
||||
"""delete all matching item by status"""
|
||||
data = {"query": {"term": {"status": {"value": self.status}}}}
|
||||
must_list = [{"term": {"status": {"value": self.status}}}]
|
||||
if channel_id:
|
||||
must_list.append({"term": {"channel_id": {"value": channel_id}}})
|
||||
|
||||
if vid_type:
|
||||
must_list.append({"term": {"vid_type": {"value": vid_type}}})
|
||||
|
||||
data = {"query": {"bool": {"must": must_list}}}
|
||||
|
||||
path = "ta_download/_delete_by_query"
|
||||
_, _ = ElasticWrap(path).post(data=data)
|
||||
|
||||
|
|
|
|||
|
|
@ -138,9 +138,18 @@ class DownloadApiListView(ApiBaseView):
|
|||
validated_query = serializer.validated_data
|
||||
|
||||
query_filter = validated_query["filter"]
|
||||
channel = validated_query.get("channel")
|
||||
vid_type = validated_query.get("vid_type")
|
||||
message = f"delete queue by status: {query_filter}"
|
||||
if channel:
|
||||
message += f" - filter by channel: {channel}"
|
||||
if vid_type:
|
||||
message += f" - filter by vid_type: {vid_type}"
|
||||
|
||||
print(message)
|
||||
PendingInteract(status=query_filter).delete_by_status()
|
||||
PendingInteract(status=query_filter).delete_bulk(
|
||||
channel_id=channel, vid_type=vid_type
|
||||
)
|
||||
|
||||
return Response(status=204)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue