added migrationID tag for fast lookup

master
cheetah 5 months ago
parent 3ab4b38bac
commit 8031513319

@ -6,6 +6,8 @@ import (
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"os" "os"
"path"
"strings"
"time" "time"
"git.cheetah.cat/worksucc/gma-puzzles/gma" "git.cheetah.cat/worksucc/gma-puzzles/gma"
@ -19,6 +21,8 @@ type DB_GMA struct {
ProcessingEnd time.Time `json:"processingEnd"` ProcessingEnd time.Time `json:"processingEnd"`
ProcessingDuration int64 `json:"processingDuration"` ProcessingDuration int64 `json:"processingDuration"`
MigrationID string `json:"migrationID"`
OriginalPath string `json:"originalPath"` OriginalPath string `json:"originalPath"`
StatModTime time.Time `json:"statModTime"` StatModTime time.Time `json:"statModTime"`
GMASize int64 `json:"archiveSize"` GMASize int64 `json:"archiveSize"`
@ -31,9 +35,10 @@ type DB_GMA struct {
RetryCounter int `json:"retries"` RetryCounter int `json:"retries"`
} }
type DB_GMA_Alias struct { type DB_GMA_Alias struct {
Path string `json:"path"` MigrationID string `json:"migrationID"`
Hash string `json:"hash"` Path string `json:"path"`
Deleted bool `json:"deleted"` Hash string `json:"hash"`
Deleted bool `json:"deleted"`
} }
type DB_GMADeletionData struct { type DB_GMADeletionData struct {
Deleted bool `json:"deleted"` Deleted bool `json:"deleted"`
@ -222,3 +227,7 @@ func (s *semaphore) Release() {
func (s *semaphore) Close() { func (s *semaphore) Close() {
close(s.semC) close(s.semC)
} }
func CreateMigrationID(filePath string) string {
return strings.ReplaceAll(strings.ReplaceAll(path.Base(filePath), ".gma", ""), ".", "_")
}

@ -619,6 +619,7 @@ func DeleteIfSafeGMA(pw progress.Writer, filePath string) (err error) {
if dboGMA_sameHash.OriginalPath != filePath { if dboGMA_sameHash.OriginalPath != filePath {
pw.Log("originalpath differs for this hash") pw.Log("originalpath differs for this hash")
// DB_GMA_Alias // DB_GMA_Alias
dboGMA.OriginalPath = dboGMA_sameHash.OriginalPath
} }
} }
if dboGMA.OriginalPath == filePath { if dboGMA.OriginalPath == filePath {
@ -657,21 +658,20 @@ func DeleteIfSafeGMA(pw progress.Writer, filePath string) (err error) {
return fmt.Errorf("650-: %v", err) return fmt.Errorf("650-: %v", err)
} }
if originalDeletionData.Deleted { if originalDeletionData.Deleted {
pw.Log(filepath.Base(filePath))
pw.Log(filepath.Base(dboGMA_sameHash.OriginalPath))
pw.Log("")
aliasData := common.DB_GMA_Alias{ aliasData := common.DB_GMA_Alias{
Path: filePath, Path: filePath,
Hash: dboGMA.GMAHash, Hash: dboGMA.GMAHash,
Deleted: true, Deleted: true,
MigrationID: common.CreateMigrationID(filePath),
} }
recoveryPath := filepath.Join("/zpool0/cheetah/workshop/garrysmod/gma-inator/recovery-tree", fmt.Sprintf("%s.json", dboGMA.OriginalPath)) err = os.Remove(aliasData.Path)
if checkFileExists(recoveryPath) { if err != nil {
err = os.Remove(aliasData.Path) return err
if err != nil {
return err
}
pw.Log("deleted %s duplicate, original was %s", aliasData.Path, dboGMA.OriginalPath)
} else {
pw.Log("%s recoveryPath does not exist %s", filePath, recoveryPath)
} }
pw.Log("deleted %s", aliasData.Path)
lzmaFile := fmt.Sprintf("%s.lzma", aliasData.Path) lzmaFile := fmt.Sprintf("%s.lzma", aliasData.Path)
if checkFileExists(lzmaFile) { if checkFileExists(lzmaFile) {
err = os.Remove(lzmaFile) err = os.Remove(lzmaFile)
@ -680,7 +680,10 @@ func DeleteIfSafeGMA(pw progress.Writer, filePath string) (err error) {
} }
pw.Log("deleted %s", lzmaFile) pw.Log("deleted %s", lzmaFile)
} }
_, _ = colAliases.CreateDocument(arangoCTX, aliasData) _, err = colAliases.CreateDocument(arangoCTX, aliasData)
if err != nil {
return err
}
} else { } else {
return fmt.Errorf("originals have not been deleted") return fmt.Errorf("originals have not been deleted")
} }
@ -1208,6 +1211,7 @@ func ProcessGMA(pw progress.Writer, filePath string) (err error) {
dboGMA.ProcessingEnd = time.Now() dboGMA.ProcessingEnd = time.Now()
dboGMA.ProcessingDuration = dboGMA.ProcessingEnd.Sub(dboGMA.ProcessingStart).Milliseconds() dboGMA.ProcessingDuration = dboGMA.ProcessingEnd.Sub(dboGMA.ProcessingStart).Milliseconds()
dboGMA.Success = true dboGMA.Success = true
dboGMA.MigrationID = common.CreateMigrationID(dboGMA.OriginalPath)
_, err = colGMA.UpdateDocument(arangoCTX, dboGMA.ID, dboGMA) _, err = colGMA.UpdateDocument(arangoCTX, dboGMA.ID, dboGMA)
if err != nil { if err != nil {

Loading…
Cancel
Save