mirror of
https://git.sr.ht/~cadence/cloudtube
synced 2024-11-14 12:27:28 +00:00
Keep subscriptions in database if channel deleted
This commit is contained in:
parent
deea909585
commit
0aa0505009
@ -24,7 +24,10 @@ module.exports = [
|
|||||||
|
|
||||||
if (add) {
|
if (add) {
|
||||||
await fetchChannel(ucid, settings.instance)
|
await fetchChannel(ucid, settings.instance)
|
||||||
db.prepare("INSERT OR IGNORE INTO Subscriptions (token, ucid) VALUES (?, ?)").run(token, ucid)
|
db.prepare(
|
||||||
|
"INSERT INTO Subscriptions (token, ucid) VALUES (?, ?)"
|
||||||
|
+ " ON CONFLICT (token, ucid) DO UPDATE SET channel_missing = 0"
|
||||||
|
).run(token, ucid)
|
||||||
} else {
|
} else {
|
||||||
db.prepare("DELETE FROM Subscriptions WHERE token = ? AND ucid = ?").run(token, ucid)
|
db.prepare("DELETE FROM Subscriptions WHERE token = ? AND ucid = ?").run(token, ucid)
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ const prepared = {
|
|||||||
"UPDATE Channels SET refreshed = ? WHERE ucid = ?"
|
"UPDATE Channels SET refreshed = ? WHERE ucid = ?"
|
||||||
),
|
),
|
||||||
unsubscribe_all_from_channel: db.prepare(
|
unsubscribe_all_from_channel: db.prepare(
|
||||||
"DELETE FROM Subscriptions WHERE ucid = ?"
|
"UPDATE Subscriptions SET channel_missing = 1 WHERE ucid = ?"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ class RefreshQueue {
|
|||||||
// get the next set of scheduled channels to refresh
|
// get the next set of scheduled channels to refresh
|
||||||
const afterTime = Date.now() - constants.caching.seen_token_subscriptions_eligible
|
const afterTime = Date.now() - constants.caching.seen_token_subscriptions_eligible
|
||||||
const channels = db.prepare(
|
const channels = db.prepare(
|
||||||
"SELECT DISTINCT Subscriptions.ucid FROM SeenTokens INNER JOIN Subscriptions ON SeenTokens.token = Subscriptions.token AND SeenTokens.seen > ? ORDER BY SeenTokens.seen DESC"
|
"SELECT DISTINCT Subscriptions.ucid FROM SeenTokens INNER JOIN Subscriptions ON SeenTokens.token = Subscriptions.token AND SeenTokens.seen > ? WHERE Subscriptions.channel_missing = 0 ORDER BY SeenTokens.seen DESC"
|
||||||
).pluck().all(afterTime)
|
).pluck().all(afterTime)
|
||||||
this.addLast(channels)
|
this.addLast(channels)
|
||||||
this.lastLoadTime = Date.now()
|
this.lastLoadTime = Date.now()
|
||||||
|
@ -51,7 +51,7 @@ class User {
|
|||||||
|
|
||||||
getSubscriptions() {
|
getSubscriptions() {
|
||||||
if (this.token) {
|
if (this.token) {
|
||||||
return db.prepare("SELECT ucid FROM Subscriptions WHERE token = ?").pluck().all(this.token)
|
return db.prepare("SELECT ucid FROM Subscriptions WHERE token = ? AND channel_missing = 0").pluck().all(this.token)
|
||||||
} else {
|
} else {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ class User {
|
|||||||
|
|
||||||
isSubscribed(ucid) {
|
isSubscribed(ucid) {
|
||||||
if (this.token) {
|
if (this.token) {
|
||||||
return !!db.prepare("SELECT * FROM Subscriptions WHERE token = ? AND ucid = ?").get([this.token, ucid])
|
return !!db.prepare("SELECT * FROM Subscriptions WHERE token = ? AND ucid = ? AND channel_missing = 0").get([this.token, ucid])
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,11 @@ const deltas = [
|
|||||||
function() {
|
function() {
|
||||||
db.prepare("ALTER TABLE Settings ADD COLUMN recommended_mode INTEGER DEFAULT 0")
|
db.prepare("ALTER TABLE Settings ADD COLUMN recommended_mode INTEGER DEFAULT 0")
|
||||||
.run()
|
.run()
|
||||||
|
},
|
||||||
|
// 8: Subscriptions +channel_missing
|
||||||
|
function() {
|
||||||
|
db.prepare("ALTER TABLE Subscriptions ADD COLUMN channel_missing INTEGER DEFAULT 0")
|
||||||
|
.run()
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user