mirror of
https://github.com/stashapp/stash.git
synced 2026-05-09 05:05:29 +02:00
Fix
This commit is contained in:
parent
e29fd8a0a6
commit
81f890be58
3 changed files with 12 additions and 49 deletions
|
|
@ -39,7 +39,6 @@ type FingerprintSubmissionReader interface {
|
|||
type FingerprintSubmissionWriter interface {
|
||||
Create(ctx context.Context, newObject *FingerprintSubmission) error
|
||||
Delete(ctx context.Context, endpoint string, stashID string) error
|
||||
DeleteByEndpoint(ctx context.Context, endpoint string) error
|
||||
}
|
||||
|
||||
type FingerprintSubmissionReaderWriter interface {
|
||||
|
|
|
|||
|
|
@ -85,18 +85,6 @@ func (qb *FingerprintSubmissionStore) Delete(ctx context.Context, endpoint strin
|
|||
return nil
|
||||
}
|
||||
|
||||
func (qb *FingerprintSubmissionStore) DeleteByEndpoint(ctx context.Context, endpoint string) error {
|
||||
q := dialect.Delete(qb.table()).Where(
|
||||
qb.table().Col("endpoint").Eq(endpoint),
|
||||
)
|
||||
|
||||
if _, err := exec(ctx, q); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qb *FingerprintSubmissionStore) FindByEndpoint(ctx context.Context, endpoint string) ([]*models.FingerprintSubmission, error) {
|
||||
q := qb.selectDataset().Where(
|
||||
qb.table().Col("endpoint").Eq(endpoint),
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
func TestFingerprintSubmissionCreate(t *testing.T) {
|
||||
withTxn(func(ctx context.Context) error {
|
||||
submission := &models.FingerprintSubmission{
|
||||
Endpoint: "https://stashdb.org/graphql",
|
||||
Endpoint: "https://endpoint1.example.org/graphql",
|
||||
StashID: "test-stash-id-1",
|
||||
SceneID: sceneIDs[sceneIdxWithGallery],
|
||||
Vote: models.FingerprintVoteInvalid,
|
||||
|
|
@ -40,7 +40,7 @@ func TestFingerprintSubmissionCreate(t *testing.T) {
|
|||
func TestFingerprintSubmissionCreateDuplicate(t *testing.T) {
|
||||
withTxn(func(ctx context.Context) error {
|
||||
submission := &models.FingerprintSubmission{
|
||||
Endpoint: "https://stashdb.org/graphql",
|
||||
Endpoint: "https://endpoint2.example.org/graphql",
|
||||
StashID: "test-stash-id-dup",
|
||||
SceneID: sceneIDs[sceneIdxWithGallery],
|
||||
Vote: models.FingerprintVoteValid,
|
||||
|
|
@ -52,7 +52,7 @@ func TestFingerprintSubmissionCreateDuplicate(t *testing.T) {
|
|||
|
||||
// Creating again with same endpoint+stash_id should not error (ON CONFLICT DO NOTHING)
|
||||
submission2 := &models.FingerprintSubmission{
|
||||
Endpoint: "https://stashdb.org/graphql",
|
||||
Endpoint: "https://endpoint2.example.org/graphql",
|
||||
StashID: "test-stash-id-dup",
|
||||
SceneID: sceneIDs[sceneIdxWithPerformer],
|
||||
Vote: models.FingerprintVoteInvalid,
|
||||
|
|
@ -74,7 +74,7 @@ func TestFingerprintSubmissionCreateDuplicate(t *testing.T) {
|
|||
|
||||
func TestFingerprintSubmissionFindByEndpoint(t *testing.T) {
|
||||
withTxn(func(ctx context.Context) error {
|
||||
endpoint := "https://test-endpoint.org/graphql"
|
||||
endpoint := "https://endpoint3.example.org/graphql"
|
||||
|
||||
// Create multiple submissions for the same endpoint
|
||||
for i := 0; i < 3; i++ {
|
||||
|
|
@ -91,7 +91,7 @@ func TestFingerprintSubmissionFindByEndpoint(t *testing.T) {
|
|||
|
||||
// Create one for a different endpoint
|
||||
otherSubmission := &models.FingerprintSubmission{
|
||||
Endpoint: "https://other-endpoint.org/graphql",
|
||||
Endpoint: "https://endpoint4.example.org/graphql",
|
||||
StashID: "other-stash-id",
|
||||
SceneID: sceneIDs[sceneIdxWithGallery],
|
||||
Vote: models.FingerprintVoteValid,
|
||||
|
|
@ -112,7 +112,7 @@ func TestFingerprintSubmissionFindByEndpoint(t *testing.T) {
|
|||
func TestFingerprintSubmissionDelete(t *testing.T) {
|
||||
withTxn(func(ctx context.Context) error {
|
||||
submission := &models.FingerprintSubmission{
|
||||
Endpoint: "https://delete-test.org/graphql",
|
||||
Endpoint: "https://endpoint5.example.org/graphql",
|
||||
StashID: "delete-test-stash-id",
|
||||
SceneID: sceneIDs[sceneIdxWithGallery],
|
||||
Vote: models.FingerprintVoteInvalid,
|
||||
|
|
@ -122,12 +122,17 @@ func TestFingerprintSubmissionDelete(t *testing.T) {
|
|||
err := db.FingerprintSubmission.Create(ctx, submission)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Verify it was created
|
||||
found, err := db.FingerprintSubmission.FindByEndpoint(ctx, submission.Endpoint)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, found, 1)
|
||||
|
||||
// Delete it
|
||||
err = db.FingerprintSubmission.Delete(ctx, submission.Endpoint, submission.StashID)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Verify it's gone
|
||||
found, err := db.FingerprintSubmission.FindByEndpoint(ctx, submission.Endpoint)
|
||||
found, err = db.FingerprintSubmission.FindByEndpoint(ctx, submission.Endpoint)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, found, 0)
|
||||
|
||||
|
|
@ -135,32 +140,3 @@ func TestFingerprintSubmissionDelete(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestFingerprintSubmissionDeleteByEndpoint(t *testing.T) {
|
||||
withTxn(func(ctx context.Context) error {
|
||||
endpoint := "https://delete-all-test.org/graphql"
|
||||
|
||||
// Create multiple submissions
|
||||
for i := 0; i < 3; i++ {
|
||||
submission := &models.FingerprintSubmission{
|
||||
Endpoint: endpoint,
|
||||
StashID: "delete-all-stash-id-" + string(rune('a'+i)),
|
||||
SceneID: sceneIDs[sceneIdxWithGallery],
|
||||
Vote: models.FingerprintVoteInvalid,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
err := db.FingerprintSubmission.Create(ctx, submission)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
// Delete all by endpoint
|
||||
err := db.FingerprintSubmission.DeleteByEndpoint(ctx, endpoint)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Verify all are gone
|
||||
found, err := db.FingerprintSubmission.FindByEndpoint(ctx, endpoint)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, found, 0)
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue