[Files Refactor] Performance tuning (#2819)

* Load scene relationships on demand
* Load image relationships on demand
* Load gallery relationships on demand
* Add dataloaden
* Use dataloaders
* Use where in for other find many functions
This commit is contained in:
WithoutPants
2022-08-12 12:21:46 +10:00
parent 9b31b20fed
commit 00608c167a
317 changed files with 28002 additions and 14875 deletions

View File

@@ -12,8 +12,8 @@ import (
)
type stashIDReaderWriter interface {
GetStashIDs(ctx context.Context, performerID int) ([]*models.StashID, error)
UpdateStashIDs(ctx context.Context, performerID int, stashIDs []*models.StashID) error
GetStashIDs(ctx context.Context, performerID int) ([]models.StashID, error)
UpdateStashIDs(ctx context.Context, performerID int, stashIDs []models.StashID) error
}
func testStashIDReaderWriter(ctx context.Context, t *testing.T, r stashIDReaderWriter, id int) {
@@ -26,25 +26,25 @@ func testStashIDReaderWriter(ctx context.Context, t *testing.T, r stashIDReaderW
// add stash ids
const stashIDStr = "stashID"
const endpoint = "endpoint"
stashID := &models.StashID{
stashID := models.StashID{
StashID: stashIDStr,
Endpoint: endpoint,
}
// update stash ids and ensure was updated
if err := r.UpdateStashIDs(ctx, id, []*models.StashID{stashID}); err != nil {
if err := r.UpdateStashIDs(ctx, id, []models.StashID{stashID}); err != nil {
t.Error(err.Error())
}
testStashIDs(ctx, t, r, id, []*models.StashID{stashID})
testStashIDs(ctx, t, r, id, []models.StashID{stashID})
// update non-existing id - should return error
if err := r.UpdateStashIDs(ctx, -1, []*models.StashID{stashID}); err == nil {
if err := r.UpdateStashIDs(ctx, -1, []models.StashID{stashID}); err == nil {
t.Error("expected error when updating non-existing id")
}
// remove stash ids and ensure was updated
if err := r.UpdateStashIDs(ctx, id, []*models.StashID{}); err != nil {
if err := r.UpdateStashIDs(ctx, id, []models.StashID{}); err != nil {
t.Error(err.Error())
}
@@ -62,7 +62,7 @@ func testNoStashIDs(ctx context.Context, t *testing.T, r stashIDReaderWriter, id
assert.Len(t, stashIDs, 0)
}
func testStashIDs(ctx context.Context, t *testing.T, r stashIDReaderWriter, id int, expected []*models.StashID) {
func testStashIDs(ctx context.Context, t *testing.T, r stashIDReaderWriter, id int, expected []models.StashID) {
t.Helper()
stashIDs, err := r.GetStashIDs(ctx, id)
if err != nil {