Skip to content

Commit

Permalink
Change To Seperate column for Date Linked
Browse files Browse the repository at this point in the history
  • Loading branch information
toshski committed Dec 8, 2023
1 parent c951808 commit 5c5f86f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
7 changes: 7 additions & 0 deletions pkg/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},
Expand Down
9 changes: 5 additions & 4 deletions pkg/models/model_external_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/models/model_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
40 changes: 29 additions & 11 deletions pkg/tasks/alternate_scene_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()})
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/scenes/Filters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<option value="last_opened_asc">↑ {{ $t("Last viewed date") }}</option>
<option value="script_published_desc">↓ {{ $t("Published Script Added") }}</option>
<option value="scene_id_desc">↓ {{ $t("Scene Id") }}</option>
<option value="alt_src_desc">↓ {{ $t("Released on Alternate Sites") }}</option>
<option value="alt_src_desc">↓ {{ $t("Linked to Alternate Sites") }}</option>
<option value="random">↯ {{ $t("Random") }}</option>
</select>
</div>
Expand Down

0 comments on commit 5c5f86f

Please sign in to comment.