Attempt to fix proclamation sync
internal/sync/sync.go: Return proclamations after updating. internal/page/proclamationOptions: Handle sync return value and fallback to db if empty
This commit is contained in:
@@ -81,9 +81,15 @@ func (p *ProclamationOptions) Init(ctx *PageCtx) error {
|
|||||||
p.isSearchActive = false
|
p.isSearchActive = false
|
||||||
p.scrollTrackWidth = 30
|
p.scrollTrackWidth = 30
|
||||||
p.scrollTrackX = p.ScreenWidth - p.scrollTrackWidth
|
p.scrollTrackX = p.ScreenWidth - p.scrollTrackWidth
|
||||||
|
var err error
|
||||||
|
|
||||||
// Syncronize proclamations first
|
// Syncronize proclamations first
|
||||||
sync.SyncProclamations(ctx.DbPtr)
|
var allProcs []db.Proclamation
|
||||||
|
allProcs, err = sync.SyncProclamations(ctx.DbPtr)
|
||||||
|
if err != nil {
|
||||||
|
// sync failed, fallback to database
|
||||||
|
ctx.DbPtr.Find(&allProcs)
|
||||||
|
}
|
||||||
|
|
||||||
fm := fontManager.Get()
|
fm := fontManager.Get()
|
||||||
font, _ := fm.GetFont("Roboto-Regular")
|
font, _ := fm.GetFont("Roboto-Regular")
|
||||||
@@ -108,7 +114,7 @@ func (p *ProclamationOptions) Init(ctx *PageCtx) error {
|
|||||||
|
|
||||||
// Load current selections
|
// Load current selections
|
||||||
var selected []db.Proclamation
|
var selected []db.Proclamation
|
||||||
p.Context.DbPtr.Where("selected = ?", true).Where("id != ?", defaultProclamationID).Find(&selected)
|
ctx.DbPtr.Where("selected = ?", true).Where("id != ?", defaultProclamationID).Find(&selected)
|
||||||
for _, s := range selected {
|
for _, s := range selected {
|
||||||
if s.ID == defaultProclamationID {
|
if s.ID == defaultProclamationID {
|
||||||
logger.Debug("Found default proclamation in selected list: %s", s.ID)
|
logger.Debug("Found default proclamation in selected list: %s", s.ID)
|
||||||
@@ -116,13 +122,6 @@ func (p *ProclamationOptions) Init(ctx *PageCtx) error {
|
|||||||
p.activeMap[s.ID] = true
|
p.activeMap[s.ID] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load ALL proclamations into a lookup map for SearchText population
|
|
||||||
var allProcs []db.Proclamation
|
|
||||||
if err := p.Context.DbPtr.Where("id != ?", defaultProclamationID).Find(&allProcs).Error; err != nil {
|
|
||||||
logger.Error("Failed to fetch proclamations: %s", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
procContentMap := make(map[string]string, len(allProcs))
|
procContentMap := make(map[string]string, len(allProcs))
|
||||||
for _, pr := range allProcs {
|
for _, pr := range allProcs {
|
||||||
if pr.ID == defaultProclamationID {
|
if pr.ID == defaultProclamationID {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ func SyncProclamations(database *gorm.DB) ([]db.Proclamation, error) {
|
|||||||
|
|
||||||
var storedProclamationSettings []db.Proclamation
|
var storedProclamationSettings []db.Proclamation
|
||||||
database.Select("ID", "Selected").Find(&storedProclamationSettings)
|
database.Select("ID", "Selected").Find(&storedProclamationSettings)
|
||||||
|
|
||||||
// [ID]Selected
|
// [ID]Selected
|
||||||
stash := make(map[string]bool)
|
stash := make(map[string]bool)
|
||||||
for _, row := range storedProclamationSettings {
|
for _, row := range storedProclamationSettings {
|
||||||
@@ -76,6 +77,7 @@ func SyncProclamations(database *gorm.DB) ([]db.Proclamation, error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return nil as err for this statement, does not exit the function
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user