Skip to content

Commit

Permalink
as: Remove stored recent metadata when using single frame GLS query
Browse files Browse the repository at this point in the history
  • Loading branch information
cvetkovski98 committed Jul 3, 2023
1 parent 6447bd4 commit a44d2fd
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions pkg/applicationserver/io/packages/loragls/v3/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,7 @@ func (p *GeolocationPackage) HandleUp(
switch m := up.Up.(type) {
case *ttnpb.ApplicationUp_UplinkMessage:
pkgAssocIDs := assocIDs(def, assoc, up.EndDeviceIds)
assoc, err := p.pushUplink(ctx, pkgAssocIDs, m.UplinkMessage, data)
if err != nil {
return err
}

data, err = p.mergePackageData(def, assoc)
if err != nil {
if err := p.pushUplink(ctx, pkgAssocIDs, m.UplinkMessage, data); err != nil {
return err
}

Expand Down Expand Up @@ -188,36 +182,45 @@ func (p *GeolocationPackage) pushUplink(
ids *ttnpb.ApplicationPackageAssociationIdentifiers,
up *ttnpb.ApplicationUplink,
data *Data,
) (*ttnpb.ApplicationPackageAssociation, error) {
) error {
windowSize := constrainedWindowSize(data.MultiFrameWindowSize)

setter := func(assoc *ttnpb.ApplicationPackageAssociation) (*ttnpb.ApplicationPackageAssociation, []string, error) {
data := &Data{}
assocData := &Data{}
fieldMask := []string{"data"}

if assoc == nil {
if !data.MultiFrame {
return nil, nil, nil
}

assoc = &ttnpb.ApplicationPackageAssociation{
Ids: ids,
PackageName: PackageName,
}
fieldMask = []string{"data", "ids", "package_name"}
} else {
if err := data.FromStruct(assoc.Data); err != nil {
if err := assocData.FromStruct(assoc.Data); err != nil {
return nil, nil, err
}
}

if len(data.RecentMetadata) >= windowSize {
data.RecentMetadata = data.RecentMetadata[1:]
}
if data.MultiFrame {
if len(assocData.RecentMetadata) >= windowSize {
assocData.RecentMetadata = assocData.RecentMetadata[1:]
}

md := &UplinkMetadata{}
if err := md.FromApplicationUplink(up); err != nil {
return nil, nil, err
md := &UplinkMetadata{}
if err := md.FromApplicationUplink(up); err != nil {
return nil, nil, err
}
assocData.RecentMetadata = append(assocData.RecentMetadata, md)
} else {
assocData.RecentMetadata = nil
}
data.RecentMetadata = assocData.RecentMetadata

data.RecentMetadata = append(data.RecentMetadata, md)
st, err := data.Struct()
st, err := assocData.Struct()
if err != nil {
return nil, nil, err
}
Expand All @@ -226,7 +229,8 @@ func (p *GeolocationPackage) pushUplink(
return assoc, fieldMask, nil
}

return p.registry.SetAssociation(ctx, ids, []string{"data"}, setter)
_, err := p.registry.SetAssociation(ctx, ids, []string{"data"}, setter)
return err
}

func (*GeolocationPackage) multiFrameQuery(
Expand Down

0 comments on commit a44d2fd

Please sign in to comment.