Add Chapters for Galleries (#3289)

Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
yoshnopa
2023-03-16 05:04:54 +01:00
committed by GitHub
parent 32c91c4855
commit 7e8f941155
58 changed files with 1685 additions and 133 deletions

View File

@@ -28,7 +28,7 @@ import (
const batchSize = 50000
// create an example database by generating a number of scenes, markers,
// performers, studios and tags, and associating between them all
// performers, studios, galleries, chapters and tags, and associating between them all
type config struct {
Database string `yaml:"database"`
@@ -36,6 +36,7 @@ type config struct {
Markers int `yaml:"markers"`
Images int `yaml:"images"`
Galleries int `yaml:"galleries"`
Chapters int `yaml:"chapters"`
Performers int `yaml:"performers"`
Studios int `yaml:"studios"`
Tags int `yaml:"tags"`
@@ -97,6 +98,7 @@ func populateDB() {
makeScenes(c.Scenes)
makeImages(c.Images)
makeGalleries(c.Galleries)
makeChapters(c.Chapters)
makeMarkers(c.Markers)
}
@@ -496,6 +498,38 @@ func generateGallery(i int) models.Gallery {
}
}
func makeChapters(n int) {
logf("creating %d chapters...", n)
for i := 0; i < n; {
// do in batches of 1000
batch := i + batchSize
if err := withTxn(func(ctx context.Context) error {
for ; i < batch && i < n; i++ {
chapter := generateChapter(i)
chapter.GalleryID = models.NullInt64(int64(getRandomGallery()))
created, err := repo.GalleryChapter.Create(ctx, chapter)
if err != nil {
return err
}
}
logf("... created %d chapters", i)
return nil
}); err != nil {
panic(err)
}
}
}
func generateChapter(i int) models.GalleryChapter {
return models.GalleryChapter{
Title: names[c.Naming.Galleries].generateName(rand.Intn(7) + 1),
ImageIndex: rand.Intn(200),
}
}
func makeMarkers(n int) {
logf("creating %d markers...", n)
for i := 0; i < n; {
@@ -617,6 +651,10 @@ func getRandomScene() int {
return rand.Intn(c.Scenes) + 1
}
func getRandomGallery() int {
return rand.Intn(c.Galleries) + 1
}
func getRandomTags(ctx context.Context, min, max int) []int {
var n int
if min == max {