Skip to content

Commit

Permalink
fix: tweak user location data sync
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Trost <[email protected]>
  • Loading branch information
galexrt committed Jan 16, 2025
1 parent 58aaac4 commit 7eef884
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 42 deletions.
65 changes: 38 additions & 27 deletions gen/go/proto/resources/sync/data.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions gen/go/proto/resources/sync/data.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion gen/grpc-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7279,7 +7279,7 @@ Connect an identifier/license to the provider with the specified external id (e.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| users | [UserLocation](#resources-sync-UserLocation) | repeated | |
| clear | [bool](#bool) | optional | |
| clear_all | [bool](#bool) | optional | |



Expand Down Expand Up @@ -7328,6 +7328,7 @@ Connect an identifier/license to the provider with the specified external id (e.
| job | [string](#string) | | |
| coords | [resources.livemap.Coords](#resources-livemap-Coords) | | |
| hidden | [bool](#bool) | | |
| remove | [bool](#bool) | | |



Expand Down
2 changes: 1 addition & 1 deletion gen/ts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@fivenet-app/gen",
"private": false,
"version": "0.9.3-3",
"version": "0.9.3-4",
"license": "Apache-2.0",
"type": "module",
"repository": {
Expand Down
30 changes: 21 additions & 9 deletions gen/ts/resources/sync/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ export interface DataUserLocations {
*/
users: UserLocation[];
/**
* @generated from protobuf field: optional bool clear = 2;
* @generated from protobuf field: optional bool clear_all = 2;
*/
clear?: boolean;
clearAll?: boolean;
}
/**
* @generated from protobuf message resources.sync.UserLocation
Expand All @@ -93,6 +93,10 @@ export interface UserLocation {
* @generated from protobuf field: bool hidden = 4;
*/
hidden: boolean;
/**
* @generated from protobuf field: bool remove = 5;
*/
remove: boolean;
}
// @generated message type with reflection information, may provide speed optimized methods
class DataStatus$Type extends MessageType<DataStatus> {
Expand Down Expand Up @@ -334,7 +338,7 @@ class DataUserLocations$Type extends MessageType<DataUserLocations> {
constructor() {
super("resources.sync.DataUserLocations", [
{ no: 1, name: "users", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => UserLocation, options: { "validate.rules": { repeated: { maxItems: "2000" } } } },
{ no: 2, name: "clear", kind: "scalar", opt: true, T: 8 /*ScalarType.BOOL*/ }
{ no: 2, name: "clear_all", kind: "scalar", opt: true, T: 8 /*ScalarType.BOOL*/ }
]);
}
create(value?: PartialMessage<DataUserLocations>): DataUserLocations {
Expand All @@ -352,8 +356,8 @@ class DataUserLocations$Type extends MessageType<DataUserLocations> {
case /* repeated resources.sync.UserLocation users */ 1:
message.users.push(UserLocation.internalBinaryRead(reader, reader.uint32(), options));
break;
case /* optional bool clear */ 2:
message.clear = reader.bool();
case /* optional bool clear_all */ 2:
message.clearAll = reader.bool();
break;
default:
let u = options.readUnknownField;
Expand All @@ -370,9 +374,9 @@ class DataUserLocations$Type extends MessageType<DataUserLocations> {
/* repeated resources.sync.UserLocation users = 1; */
for (let i = 0; i < message.users.length; i++)
UserLocation.internalBinaryWrite(message.users[i], writer.tag(1, WireType.LengthDelimited).fork(), options).join();
/* optional bool clear = 2; */
if (message.clear !== undefined)
writer.tag(2, WireType.Varint).bool(message.clear);
/* optional bool clear_all = 2; */
if (message.clearAll !== undefined)
writer.tag(2, WireType.Varint).bool(message.clearAll);
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
Expand All @@ -390,14 +394,16 @@ class UserLocation$Type extends MessageType<UserLocation> {
{ no: 1, name: "identifier", kind: "scalar", T: 9 /*ScalarType.STRING*/, options: { "validate.rules": { string: { maxLen: "64" } } } },
{ no: 2, name: "job", kind: "scalar", T: 9 /*ScalarType.STRING*/, options: { "validate.rules": { string: { maxLen: "20" } } } },
{ no: 3, name: "coords", kind: "message", T: () => Coords, options: { "validate.rules": { message: { required: true } } } },
{ no: 4, name: "hidden", kind: "scalar", T: 8 /*ScalarType.BOOL*/ }
{ no: 4, name: "hidden", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
{ no: 5, name: "remove", kind: "scalar", T: 8 /*ScalarType.BOOL*/ }
]);
}
create(value?: PartialMessage<UserLocation>): UserLocation {
const message = globalThis.Object.create((this.messagePrototype!));
message.identifier = "";
message.job = "";
message.hidden = false;
message.remove = false;
if (value !== undefined)
reflectionMergePartial<UserLocation>(this, message, value);
return message;
Expand All @@ -419,6 +425,9 @@ class UserLocation$Type extends MessageType<UserLocation> {
case /* bool hidden */ 4:
message.hidden = reader.bool();
break;
case /* bool remove */ 5:
message.remove = reader.bool();
break;
default:
let u = options.readUnknownField;
if (u === "throw")
Expand All @@ -443,6 +452,9 @@ class UserLocation$Type extends MessageType<UserLocation> {
/* bool hidden = 4; */
if (message.hidden !== false)
writer.tag(4, WireType.Varint).bool(message.hidden);
/* bool remove = 5; */
if (message.remove !== false)
writer.tag(5, WireType.Varint).bool(message.remove);
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
Expand Down
3 changes: 2 additions & 1 deletion proto/resources/sync/data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ message DataLicenses {

message DataUserLocations {
repeated UserLocation users = 1 [(validate.rules).repeated.max_items = 2000];
optional bool clear = 2;
optional bool clear_all = 2;
}

message UserLocation {
string identifier = 1 [(validate.rules).string.max_len = 64];
string job = 2 [(validate.rules).string.max_len = 20];
resources.livemap.Coords coords = 3 [(validate.rules).message.required = true];
bool hidden = 4;
bool remove = 5;
}
34 changes: 33 additions & 1 deletion services/sync/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ func (s *Server) handleVehiclesData(ctx context.Context, data *pbsync.SendDataRe
func (s *Server) handleUserLocations(ctx context.Context, data *pbsync.SendDataRequest_UserLocations) (int64, error) {
tLocations := table.FivenetUserLocations

if data.UserLocations.Clear != nil && *data.UserLocations.Clear {
// Handle clear all
if data.UserLocations.ClearAll != nil && *data.UserLocations.ClearAll {
stmt := tLocations.
DELETE()

Expand All @@ -593,7 +594,14 @@ func (s *Server) handleUserLocations(ctx context.Context, data *pbsync.SendDataR
tLocations.Hidden.SET(jet.BoolExp(jet.Raw("VALUES(`hidden`)"))),
)

toDelete := []string{}
for _, location := range data.UserLocations.Users {
// Collect user locations are marked for removal
if location.Remove {
toDelete = append(toDelete, location.Identifier)
continue
}

stmt = stmt.
VALUES(
location.Identifier,
Expand All @@ -613,5 +621,29 @@ func (s *Server) handleUserLocations(ctx context.Context, data *pbsync.SendDataR
return 0, err
}

// Delete any user locations that have been marked for removal
if len(toDelete) > 0 {
identifiers := []jet.Expression{}
for _, identifier := range toDelete {
identifiers = append(identifiers, jet.String(identifier))
}

delStmt := tLocations.
DELETE().
WHERE(tLocations.Identifier.IN(identifiers...)).
LIMIT(int64(len(toDelete)))

res, err := delStmt.ExecContext(ctx, s.db)
if err != nil {
return 0, err
}

rows, err := res.RowsAffected()
if err != nil {
return 0, err
}
rowsAffected += rows
}

return rowsAffected, nil
}

0 comments on commit 7eef884

Please sign in to comment.