mirror of
https://github.com/miniflux/v2.git
synced 2025-08-06 17:41:00 +00:00
Improve user mass delete
This commit is contained in:
parent
60a7362327
commit
d3cfa6396d
1 changed files with 10 additions and 24 deletions
|
@ -7,6 +7,7 @@ package storage // import "miniflux.app/storage"
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"miniflux.app/logger"
|
"miniflux.app/logger"
|
||||||
|
@ -410,6 +411,7 @@ func (s *Storage) RemoveUserAsync(userID int64) {
|
||||||
deleteUserFeeds(s.db, userID)
|
deleteUserFeeds(s.db, userID)
|
||||||
s.db.Exec(`DELETE FROM users WHERE id=$1`, userID)
|
s.db.Exec(`DELETE FROM users WHERE id=$1`, userID)
|
||||||
s.db.Exec(`DELETE FROM integrations WHERE user_id=$1`, userID)
|
s.db.Exec(`DELETE FROM integrations WHERE user_id=$1`, userID)
|
||||||
|
logger.Debug(`[MASS DELETE] User #%d has been deleted (%d GoRoutines)`, userID, runtime.NumGoroutine())
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,18 +535,18 @@ func deleteUserFeeds(db *sql.DB, userID int64) {
|
||||||
|
|
||||||
worker := func(jobs <-chan int64, results chan<- bool) {
|
worker := func(jobs <-chan int64, results chan<- bool) {
|
||||||
for feedID := range jobs {
|
for feedID := range jobs {
|
||||||
|
logger.Debug(`[MASS DELETE] Deleting feed #%d for user #%d (%d GoRoutines)`, feedID, userID, runtime.NumGoroutine())
|
||||||
deleteUserEntries(db, userID, feedID)
|
deleteUserEntries(db, userID, feedID)
|
||||||
db.Exec(`DELETE FROM feeds WHERE id=$1`, feedID)
|
db.Exec(`DELETE FROM feeds WHERE id=$1`, feedID)
|
||||||
results <- true
|
results <- true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const numWorkers = 3
|
|
||||||
numJobs := len(feedIDs)
|
numJobs := len(feedIDs)
|
||||||
jobs := make(chan int64, numJobs)
|
jobs := make(chan int64, numJobs)
|
||||||
results := make(chan bool, numJobs)
|
results := make(chan bool, numJobs)
|
||||||
|
|
||||||
for w := 0; w < numWorkers; w++ {
|
for w := 0; w < 2; w++ {
|
||||||
go worker(jobs, results)
|
go worker(jobs, results)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -559,8 +561,7 @@ func deleteUserFeeds(db *sql.DB, userID int64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteUserEntries(db *sql.DB, userID int64, feedID int64) {
|
func deleteUserEntries(db *sql.DB, userID int64, feedID int64) {
|
||||||
query := `SELECT id FROM entries WHERE user_id=$1 AND feed_id=$2`
|
rows, err := db.Query(`SELECT id FROM entries WHERE user_id=$1 AND feed_id=$2`, userID, feedID)
|
||||||
rows, err := db.Query(query, userID, feedID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(`store: unable to get user feed entries: %v`, err)
|
logger.Error(`store: unable to get user feed entries: %v`, err)
|
||||||
return
|
return
|
||||||
|
@ -570,25 +571,10 @@ func deleteUserEntries(db *sql.DB, userID int64, feedID int64) {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var entryID int64
|
var entryID int64
|
||||||
rows.Scan(&entryID)
|
rows.Scan(&entryID)
|
||||||
deleteUserEnclosures(db, userID, entryID)
|
|
||||||
db.Exec(`DELETE FROM entries WHERE id=$1`, entryID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func deleteUserEnclosures(db *sql.DB, userID int64, entryID int64) {
|
logger.Debug(`[MASS DELETE] Deleting entry #%d for user #%d (%d GoRoutines)`, entryID, userID, runtime.NumGoroutine())
|
||||||
query := `SELECT id FROM enclosures WHERE user_id=$1 AND entry_id=$2`
|
|
||||||
rows, err := db.Query(query, userID, entryID)
|
|
||||||
if err != nil {
|
|
||||||
logger.Error(`store: unable to get user entry enclosures: %v`, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
|
|
||||||
for rows.Next() {
|
db.Exec(`DELETE FROM enclosures WHERE entry_id=$1 AND user_id=$2`, entryID, userID)
|
||||||
var enclosureID int64
|
db.Exec(`DELETE FROM entries WHERE id=$1 AND user_id=$2`, entryID, userID)
|
||||||
rows.Scan(&enclosureID)
|
|
||||||
go func() {
|
|
||||||
db.Exec(`DELETE FROM enclosures WHERE id=$1`, enclosureID)
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue