From 4ce93be2c5edc23847aabd10ff20e04020730888 Mon Sep 17 00:00:00 2001 From: Eccentric Date: Wed, 31 Jan 2024 16:20:43 +0000 Subject: [PATCH] Improve query profile --- handlers/client.go | 53 ++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/handlers/client.go b/handlers/client.go index d1098a7..d0942a9 100644 --- a/handlers/client.go +++ b/handlers/client.go @@ -44,7 +44,6 @@ func PostClientProfileAction(c *fiber.Ctx) error { "common_core": nil, "common_public": nil, } - for key := range profileSnapshots { profileSnapshots[key] = person.GetProfileFromType(key).Snapshot() } @@ -71,7 +70,8 @@ func PostClientProfileAction(c *fiber.Ctx) error { profile.Diff(profileSnapshot) } - revision, _ := strconv.Atoi(c.Query("rvn")) + known, _ := strconv.Atoi(c.Query("rvn")) + revision := known if revision == -1 { revision = profile.Revision } @@ -81,27 +81,30 @@ func PostClientProfileAction(c *fiber.Ctx) error { delete(profileSnapshots, profile.Type) multiUpdate := []aid.JSON{} - for key := range profileSnapshots { - profile := person.GetProfileFromType(key) - if profile == nil { - continue + if known != -1 { + + for key := range profileSnapshots { + profile := person.GetProfileFromType(key) + if profile == nil { + continue + } + profile.Revision++ + + if len(profile.Changes) == 0 { + continue + } + + multiUpdate = append(multiUpdate, aid.JSON{ + "profileId": profile.Type, + "profileRevision": profile.Revision, + "profileCommandRevision": profile.Revision, + "profileChangesBaseRevision": profile.Revision - 1, + "profileChanges": profile.Changes, + }) + + profile.ClearProfileChanges() + go profile.Save() } - profile.Revision++ - - if len(profile.Changes) == 0 { - continue - } - - multiUpdate = append(multiUpdate, aid.JSON{ - "profileId": profile.Type, - "profileRevision": profile.Revision, - "profileCommandRevision": profile.Revision, - "profileChangesBaseRevision": profile.Revision - 1, - "profileChanges": profile.Changes, - }) - - profile.ClearProfileChanges() - go profile.Save() } return c.Status(200).JSON(aid.JSON{ @@ -118,7 +121,11 @@ func PostClientProfileAction(c *fiber.Ctx) error { } func clientQueryProfileAction(c *fiber.Ctx, person *p.Person, profile *p.Profile, notifications *[]aid.JSON) error { - profile.CreateFullProfileUpdateChange() + known, _ := strconv.Atoi(c.Query("rvn")) + + if known == -1 { + profile.CreateFullProfileUpdateChange() + } return nil }