From 5c5f86fad13f404de2b1cead3a12b49f86757420 Mon Sep 17 00:00:00 2001 From: toshski Date: Sat, 9 Dec 2023 06:19:36 +1300 Subject: [PATCH] Change To Seperate column for Date Linked --- pkg/migrations/migrations.go | 7 +++++ pkg/models/model_external_reference.go | 9 +++--- pkg/models/model_scene.go | 3 +- pkg/tasks/alternate_scene_source.go | 40 +++++++++++++++++++------- ui/src/views/scenes/Filters.vue | 2 +- 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/pkg/migrations/migrations.go b/pkg/migrations/migrations.go index d953e23ec..3d165b646 100644 --- a/pkg/migrations/migrations.go +++ b/pkg/migrations/migrations.go @@ -768,10 +768,17 @@ func Migrate() { UdfBool2 bool `json:"udf_bool2" xbvrbackup:"udf_bool2"` UdfDatetime1 time.Time `json:"udf_datetime1" xbvrbackup:"udf_datetime1"` } + type ExternalReferenceLink struct { + UdfDatetime1 time.Time `json:"udf_datetime1" xbvrbackup:"udf_datetime1"` + } err := tx.AutoMigrate(Site{}).Error if err != nil { return err } + err = tx.AutoMigrate(ExternalReferenceLink{}).Error + if err != nil { + return err + } return tx.AutoMigrate(ExternalReference{}).Error }, }, diff --git a/pkg/models/model_external_reference.go b/pkg/models/model_external_reference.go index e73c934ab..5304f02f5 100644 --- a/pkg/models/model_external_reference.go +++ b/pkg/models/model_external_reference.go @@ -40,10 +40,11 @@ type ExternalReferenceLink struct { InternalDbId uint `json:"internal_db_id" gorm:"index" xbvrbackup:"-"` InternalNameId string `json:"internal_name_id" gorm:"index" xbvrbackup:"internal_name_id"` - ExternalReferenceID uint `json:"external_reference_id" gorm:"index" xbvrbackup:"-"` - ExternalSource string `json:"external_source" xbvrbackup:"-"` - ExternalId string `json:"external_id" gorm:"index" xbvrbackup:"-"` - MatchType int `json:"match_type" xbvrbackup:"match_type"` + ExternalReferenceID uint `json:"external_reference_id" gorm:"index" xbvrbackup:"-"` + ExternalSource string `json:"external_source" xbvrbackup:"-"` + ExternalId string `json:"external_id" gorm:"index" xbvrbackup:"-"` + MatchType int `json:"match_type" xbvrbackup:"match_type"` + UdfDatetime1 time.Time `json:"udf_datetime1" xbvrbackup:"udf_datetime1"` ExternalReference ExternalReference `json:"external_reference" gorm:"foreignKey:ExternalReferenceId" xbvrbackup:"-"` } diff --git a/pkg/models/model_scene.go b/pkg/models/model_scene.go index 1d95ba3e5..1fecc358c 100644 --- a/pkg/models/model_scene.go +++ b/pkg/models/model_scene.go @@ -1148,7 +1148,8 @@ func queryScenes(db *gorm.DB, r RequestSceneList) (*gorm.DB, *gorm.DB) { tx = tx.Order("random()") } case "alt_src_desc": - tx = tx.Order(`(select max(er.external_date) from external_reference_links erl join external_references er on er.id=erl.external_reference_id where erl.internal_table='scenes' and erl.internal_db_id=scenes.id and er.external_source like 'alternate scene %') desc`) + //tx = tx.Order(`(select max(er.external_date) from external_reference_links erl join external_references er on er.id=erl.external_reference_id where erl.internal_table='scenes' and erl.internal_db_id=scenes.id and er.external_source like 'alternate scene %') desc`) + tx = tx.Order(`(select max(erl.udf_datetime1) from external_reference_links erl where erl.internal_table='scenes' and erl.internal_db_id=scenes.id and erl.external_source like 'alternate scene %') desc`) default: tx = tx.Order("release_date desc") } diff --git a/pkg/tasks/alternate_scene_source.go b/pkg/tasks/alternate_scene_source.go index 8b7621adf..328653c8b 100644 --- a/pkg/tasks/alternate_scene_source.go +++ b/pkg/tasks/alternate_scene_source.go @@ -113,12 +113,19 @@ func MatchAlternateSources() { tmpTitle, unmatchedSceneData.MasterSiteId).Find(&possiblematchs) if len(possiblematchs) == 1 { - // create a link using - if len(altsource.XbvrLinks) == 0 || altsource.XbvrLinks[0].InternalDbId != possiblematchs[0].ID { - UpdateLinks(db, altsource.ID, models.ExternalReferenceLink{InternalTable: "scenes", InternalDbId: possiblematchs[0].ID, InternalNameId: possiblematchs[0].SceneID, - ExternalReferenceID: altsource.ID, ExternalSource: altsource.ExternalSource, ExternalId: altsource.ExternalId, MatchType: 10000}) + found := false + // check not already linked, if we update unnessarily, it will mess up the sort by "Released on Alternate Sites" sort option + for _, link := range altsource.XbvrLinks { + if link.InternalDbId == possiblematchs[0].ID { + found = true + break + } + } + if found { + log.Infof("(Debug remove me) 10000 already matched %s %v", possiblematchs[0].SceneID, altsource.ExternalId) } else { - tlog.Infof("10000 already matched %s %v", possiblematchs[0].SceneID, altsource.ExternalId) + UpdateLinks(db, altsource.ID, models.ExternalReferenceLink{InternalTable: "scenes", InternalDbId: possiblematchs[0].ID, InternalNameId: possiblematchs[0].SceneID, + ExternalReferenceID: altsource.ID, ExternalSource: altsource.ExternalSource, ExternalId: altsource.ExternalId, MatchType: 10000, UdfDatetime1: time.Now()}) } } else { // build the search query based on the sites matching params @@ -221,17 +228,28 @@ func MatchAlternateSources() { extdata.Query = q newjson, _ := json.Marshal(extdata) altsource.ExternalData = string(newjson) - // save the updated query used - altsource.Save() + tmpAltSource := altsource + tmpAltSource.XbvrLinks = nil + // save the updated query used, but don't update the links + tmpAltSource.Save() if len(searchResults.Hits) > 0 { var scene models.Scene scene.GetIfExist(searchResults.Hits[0].ID) if scene.ID > 0 { - if len(altsource.XbvrLinks) == 0 || altsource.XbvrLinks[0].InternalDbId != possiblematchs[0].ID { - UpdateLinks(db, altsource.ID, models.ExternalReferenceLink{InternalTable: "scenes", InternalDbId: scene.ID, InternalNameId: scene.SceneID, - ExternalReferenceID: altsource.ID, ExternalSource: altsource.ExternalSource, ExternalId: altsource.ExternalId, MatchType: int(searchResults.Hits[0].Score)}) + // check not already linked, if we update unnessarily, it will mess up the sort by "Released on Alternate Sites" sort option + found := false + for _, link := range altsource.XbvrLinks { + if link.InternalDbId == scene.ID { + found = true + break + } + } + if found { + log.Infof("(Debug remove me) Search result already matched %s %v", scene.SceneID, altsource.ExternalId) } else { - tlog.Infof("Search result already matched %s %v", possiblematchs[0].SceneID, altsource.ExternalId) + log.Infof("(Debug remove me) Search result new link %s %v", scene.SceneID, altsource.ExternalId) + UpdateLinks(db, altsource.ID, models.ExternalReferenceLink{InternalTable: "scenes", InternalDbId: scene.ID, InternalNameId: scene.SceneID, + ExternalReferenceID: altsource.ID, ExternalSource: altsource.ExternalSource, ExternalId: altsource.ExternalId, MatchType: int(searchResults.Hits[0].Score), UdfDatetime1: time.Now()}) } } } diff --git a/ui/src/views/scenes/Filters.vue b/ui/src/views/scenes/Filters.vue index ecc492d4f..3fcd268bd 100644 --- a/ui/src/views/scenes/Filters.vue +++ b/ui/src/views/scenes/Filters.vue @@ -57,7 +57,7 @@ - +