mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 21:16:30 +02:00
Add request batching for cf updates
This commit is contained in:
parent
3a0f083da2
commit
5c82486016
@ -30,13 +30,3 @@ type UpdateCheck struct {
|
|||||||
// If an error is returned for a mod, or from CheckUpdate, DoUpdate is not called on that mod / at all
|
// If an error is returned for a mod, or from CheckUpdate, DoUpdate is not called on that mod / at all
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
// to carry out updating:
|
|
||||||
|
|
||||||
// go through all metafiles in index
|
|
||||||
// make a []Mod for each updater, so map[string][]Mod
|
|
||||||
// for each Mod, check the "first" updater, then give the Mod to the map
|
|
||||||
|
|
||||||
// go through the map, call CheckUpdate with the []Mod
|
|
||||||
// print to user, if interactive mode
|
|
||||||
// call doupdate with the mods and interfaces!!
|
|
||||||
|
@ -206,8 +206,9 @@ type cachedStateStore struct {
|
|||||||
|
|
||||||
func (u cfUpdater) CheckUpdate(mods []core.Mod, mcVersion string) ([]core.UpdateCheck, error) {
|
func (u cfUpdater) CheckUpdate(mods []core.Mod, mcVersion string) ([]core.UpdateCheck, error) {
|
||||||
results := make([]core.UpdateCheck, len(mods))
|
results := make([]core.UpdateCheck, len(mods))
|
||||||
|
modIDs := make([]int, len(mods))
|
||||||
|
modInfos := make([]modInfo, len(mods))
|
||||||
|
|
||||||
// TODO: make this batched
|
|
||||||
for i, v := range mods {
|
for i, v := range mods {
|
||||||
projectRaw, ok := v.GetParsedUpdateData("curseforge")
|
projectRaw, ok := v.GetParsedUpdateData("curseforge")
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -215,18 +216,36 @@ func (u cfUpdater) CheckUpdate(mods []core.Mod, mcVersion string) ([]core.Update
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
project := projectRaw.(cfUpdateData)
|
project := projectRaw.(cfUpdateData)
|
||||||
modInfoData, err := getModInfo(project.ProjectID)
|
modIDs[i] = project.ProjectID
|
||||||
|
}
|
||||||
|
|
||||||
|
modInfosUnsorted, err := getModInfoMultiple(modIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
results[i] = core.UpdateCheck{Error: err}
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, v := range modInfosUnsorted {
|
||||||
|
for i, id := range modIDs {
|
||||||
|
if id == v.ID {
|
||||||
|
modInfos[i] = v
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, v := range mods {
|
||||||
|
projectRaw, ok := v.GetParsedUpdateData("curseforge")
|
||||||
|
if !ok {
|
||||||
|
results[i] = core.UpdateCheck{Error: errors.New("couldn't parse mod data")}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
project := projectRaw.(cfUpdateData)
|
||||||
|
|
||||||
updateAvailable := false
|
updateAvailable := false
|
||||||
fileID := project.FileID
|
fileID := project.FileID
|
||||||
fileInfoObtained := false
|
fileInfoObtained := false
|
||||||
var fileInfoData modFileInfo
|
var fileInfoData modFileInfo
|
||||||
|
|
||||||
for _, file := range modInfoData.GameVersionLatestFiles {
|
for _, file := range modInfos[i].GameVersionLatestFiles {
|
||||||
// TODO: change to timestamp-based comparison??
|
// TODO: change to timestamp-based comparison??
|
||||||
// TODO: manage alpha/beta/release correctly, check update channel?
|
// TODO: manage alpha/beta/release correctly, check update channel?
|
||||||
// Choose "newest" version by largest ID
|
// Choose "newest" version by largest ID
|
||||||
@ -242,7 +261,7 @@ func (u cfUpdater) CheckUpdate(mods []core.Mod, mcVersion string) ([]core.Update
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The API also provides some files inline, because that's efficient!
|
// The API also provides some files inline, because that's efficient!
|
||||||
for _, file := range modInfoData.LatestFiles {
|
for _, file := range modInfos[i].LatestFiles {
|
||||||
if file.ID == fileID {
|
if file.ID == fileID {
|
||||||
fileInfoObtained = true
|
fileInfoObtained = true
|
||||||
fileInfoData = file
|
fileInfoData = file
|
||||||
@ -260,7 +279,7 @@ func (u cfUpdater) CheckUpdate(mods []core.Mod, mcVersion string) ([]core.Update
|
|||||||
results[i] = core.UpdateCheck{
|
results[i] = core.UpdateCheck{
|
||||||
UpdateAvailable: true,
|
UpdateAvailable: true,
|
||||||
UpdateString: v.FileName + " -> " + fileInfoData.FileName,
|
UpdateString: v.FileName + " -> " + fileInfoData.FileName,
|
||||||
CachedState: cachedStateStore{modInfoData, fileInfoData},
|
CachedState: cachedStateStore{modInfos[i], fileInfoData},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results, nil
|
return results, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user