2019-04-28 22:43:52 +02:00
|
|
|
package org.schabi.newpipe.database.feed.dao
|
|
|
|
|
|
|
|
import androidx.room.Dao
|
|
|
|
import androidx.room.Insert
|
|
|
|
import androidx.room.OnConflictStrategy
|
|
|
|
import androidx.room.Query
|
|
|
|
import io.reactivex.Flowable
|
|
|
|
import org.schabi.newpipe.database.feed.model.FeedEntity
|
|
|
|
import org.schabi.newpipe.database.stream.model.StreamEntity
|
2019-04-28 22:43:54 +02:00
|
|
|
import java.util.*
|
2019-04-28 22:43:52 +02:00
|
|
|
|
|
|
|
@Dao
|
|
|
|
abstract class FeedDAO {
|
|
|
|
@Query("DELETE FROM feed")
|
|
|
|
abstract fun deleteAll(): Int
|
|
|
|
|
|
|
|
@Query("""
|
|
|
|
SELECT s.* FROM streams s
|
|
|
|
|
|
|
|
INNER JOIN feed f
|
|
|
|
ON s.uid = f.stream_id
|
|
|
|
|
2019-04-28 22:43:54 +02:00
|
|
|
ORDER BY s.upload_date IS NULL DESC, s.upload_date DESC, s.uploader ASC
|
|
|
|
|
|
|
|
LIMIT 500
|
2019-04-28 22:43:52 +02:00
|
|
|
""")
|
|
|
|
abstract fun getAllStreams(): Flowable<List<StreamEntity>>
|
|
|
|
|
|
|
|
@Query("""
|
|
|
|
SELECT s.* FROM streams s
|
|
|
|
|
|
|
|
INNER JOIN feed f
|
|
|
|
ON s.uid = f.stream_id
|
|
|
|
|
|
|
|
INNER JOIN feed_group_subscription_join fgs
|
|
|
|
ON fgs.subscription_id = f.subscription_id
|
|
|
|
|
|
|
|
INNER JOIN feed_group fg
|
|
|
|
ON fg.uid = fgs.group_id
|
|
|
|
|
|
|
|
WHERE fgs.group_id = :groupId
|
2019-04-28 22:43:54 +02:00
|
|
|
|
|
|
|
ORDER BY s.upload_date IS NULL DESC, s.upload_date DESC, s.uploader ASC
|
|
|
|
LIMIT 500
|
2019-04-28 22:43:52 +02:00
|
|
|
""")
|
|
|
|
abstract fun getAllStreamsFromGroup(groupId: Long): Flowable<List<StreamEntity>>
|
|
|
|
|
2019-04-28 22:43:54 +02:00
|
|
|
@Query("""
|
|
|
|
DELETE FROM feed WHERE
|
|
|
|
|
|
|
|
feed.stream_id IN (
|
|
|
|
SELECT s.uid FROM streams s
|
|
|
|
|
|
|
|
INNER JOIN feed f
|
|
|
|
ON s.uid = f.stream_id
|
|
|
|
|
|
|
|
WHERE s.upload_date < :date
|
|
|
|
)
|
|
|
|
""")
|
|
|
|
abstract fun unlinkStreamsOlderThan(date: Date)
|
|
|
|
|
|
|
|
@Query("""
|
|
|
|
DELETE FROM feed
|
|
|
|
|
|
|
|
WHERE feed.subscription_id = :subscriptionId
|
|
|
|
|
|
|
|
AND feed.stream_id IN (
|
|
|
|
SELECT s.uid FROM streams s
|
|
|
|
|
|
|
|
INNER JOIN feed f
|
|
|
|
ON s.uid = f.stream_id
|
|
|
|
|
|
|
|
WHERE s.stream_type = "LIVE_STREAM" OR s.stream_type = "AUDIO_LIVE_STREAM"
|
|
|
|
)
|
|
|
|
""")
|
|
|
|
abstract fun unlinkOldLivestreams(subscriptionId: Long)
|
|
|
|
|
|
|
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
2019-04-28 22:43:52 +02:00
|
|
|
abstract fun insert(feedEntity: FeedEntity)
|
|
|
|
|
2019-04-28 22:43:54 +02:00
|
|
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
2019-04-28 22:43:52 +02:00
|
|
|
abstract fun insertAll(entities: List<FeedEntity>): List<Long>
|
|
|
|
}
|