diff --git a/db/query/geometries.sql b/db/query/geometries.sql index 0399cf0..5c96615 100644 --- a/db/query/geometries.sql +++ b/db/query/geometries.sql @@ -9,11 +9,17 @@ RETURNING id, geo_type, draw_geometry, bound_with, time_start, time_end, project is_deleted, created_at, updated_at; -- name: GetGeometryById :one -SELECT id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id, - ST_XMin(bbox)::float8 as min_lng, ST_YMin(bbox)::float8 as min_lat, ST_XMax(bbox)::float8 as max_lng, ST_YMax(bbox)::float8 as max_lat, - is_deleted, created_at, updated_at +SELECT geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id, + ST_XMin(geometries.bbox)::float8 as min_lng, ST_YMin(geometries.bbox)::float8 as min_lat, ST_XMax(geometries.bbox)::float8 as max_lng, ST_YMax(geometries.bbox)::float8 as max_lat, + geometries.is_deleted, geometries.created_at, geometries.updated_at, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = geometries.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM geometries -WHERE id = $1 AND is_deleted = false; +WHERE geometries.id = $1 AND geometries.is_deleted = false; -- name: UpdateGeometry :one UPDATE geometries @@ -52,7 +58,13 @@ SELECT ST_YMin(g.bbox)::float8 as min_lat, ST_XMax(g.bbox)::float8 as max_lng, ST_YMax(g.bbox)::float8 as max_lat, - g.is_deleted, g.created_at, g.updated_at + g.is_deleted, g.created_at, g.updated_at, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = g.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM geometries g WHERE g.is_deleted = false AND (sqlc.narg('project_id')::uuid IS NULL OR g.project_id = sqlc.narg('project_id')::uuid) @@ -116,7 +128,13 @@ SELECT g.draw_geometry, g.bound_with, g.time_start, - g.time_end + g.time_end, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = g.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM matched_entities me LEFT JOIN entity_geometries eg ON eg.entity_id = me.id @@ -143,25 +161,37 @@ WHERE project_id = $1; -- name: GetGeometriesByIDs :many SELECT - id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id, - ST_XMin(bbox)::float8 as min_lng, - ST_YMin(bbox)::float8 as min_lat, - ST_XMax(bbox)::float8 as max_lng, - ST_YMax(bbox)::float8 as max_lat, - is_deleted, created_at, updated_at + geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id, + ST_XMin(geometries.bbox)::float8 as min_lng, + ST_YMin(geometries.bbox)::float8 as min_lat, + ST_XMax(geometries.bbox)::float8 as max_lng, + ST_YMax(geometries.bbox)::float8 as max_lat, + geometries.is_deleted, geometries.created_at, geometries.updated_at, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = geometries.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM geometries -WHERE id = ANY($1::uuid[]) AND is_deleted = false; +WHERE geometries.id = ANY($1::uuid[]) AND geometries.is_deleted = false; -- name: GetGeometriesByProjectId :many SELECT - id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id, - ST_XMin(bbox)::float8 as min_lng, - ST_YMin(bbox)::float8 as min_lat, - ST_XMax(bbox)::float8 as max_lng, - ST_YMax(bbox)::float8 as max_lat, - is_deleted, created_at, updated_at + geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id, + ST_XMin(geometries.bbox)::float8 as min_lng, + ST_YMin(geometries.bbox)::float8 as min_lat, + ST_XMax(geometries.bbox)::float8 as max_lng, + ST_YMax(geometries.bbox)::float8 as max_lat, + geometries.is_deleted, geometries.created_at, geometries.updated_at, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = geometries.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM geometries -WHERE project_id = $1 AND is_deleted = false; +WHERE geometries.project_id = $1 AND geometries.is_deleted = false; -- name: DeleteGeometriesByIDs :exec UPDATE geometries @@ -186,7 +216,13 @@ SELECT g.draw_geometry, g.bound_with, g.time_start, - g.time_end + g.time_end, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = g.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM ( SELECT unnest(@entity_ids::uuid[]) as eid, unnest(@geometry_ids::uuid[]) as gid ) as pairs @@ -198,11 +234,17 @@ AND g.is_deleted = false; -- name: GetGeometriesByBoundWith :many SELECT - id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id, - ST_XMin(bbox)::float8 as min_lng, - ST_YMin(bbox)::float8 as min_lat, - ST_XMax(bbox)::float8 as max_lng, - ST_YMax(bbox)::float8 as max_lat, - is_deleted, created_at, updated_at + geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id, + ST_XMin(geometries.bbox)::float8 as min_lng, + ST_YMin(geometries.bbox)::float8 as min_lat, + ST_XMax(geometries.bbox)::float8 as max_lng, + ST_YMax(geometries.bbox)::float8 as max_lat, + geometries.is_deleted, geometries.created_at, geometries.updated_at, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = geometries.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM geometries -WHERE bound_with = $1 AND is_deleted = false; +WHERE geometries.bound_with = $1 AND geometries.is_deleted = false; diff --git a/internal/dtos/response/geometry.go b/internal/dtos/response/geometry.go index 877cfb2..0d5d481 100644 --- a/internal/dtos/response/geometry.go +++ b/internal/dtos/response/geometry.go @@ -22,6 +22,7 @@ type GeometryResponse struct { Bbox *Bbox `json:"bbox,omitempty"` ProjectID string `json:"project_id"` IsDeleted bool `json:"is_deleted,omitempty"` + ReplayIDs []string `json:"replay_ids,omitempty"` CreatedAt *time.Time `json:"created_at,omitempty"` UpdatedAt *time.Time `json:"updated_at,omitempty"` } diff --git a/internal/dtos/response/geometryEntitySearch.go b/internal/dtos/response/geometryEntitySearch.go index 46869c4..e546a9e 100644 --- a/internal/dtos/response/geometryEntitySearch.go +++ b/internal/dtos/response/geometryEntitySearch.go @@ -21,4 +21,5 @@ type EntityGeometrySearchGeo struct { BoundWith *string `json:"bound_with,omitempty"` TimeStart *int32 `json:"time_start,omitempty"` TimeEnd *int32 `json:"time_end,omitempty"` + ReplayIDs []string `json:"replay_ids,omitempty"` } diff --git a/internal/gen/sqlc/geometries.sql.go b/internal/gen/sqlc/geometries.sql.go index 744ccc0..99cf9f9 100644 --- a/internal/gen/sqlc/geometries.sql.go +++ b/internal/gen/sqlc/geometries.sql.go @@ -201,7 +201,13 @@ SELECT g.draw_geometry, g.bound_with, g.time_start, - g.time_end + g.time_end, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = g.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM ( SELECT unnest($1::uuid[]) as eid, unnest($2::uuid[]) as gid ) as pairs @@ -227,6 +233,7 @@ type GetEntityGeometriesByPairsRow struct { BoundWith pgtype.UUID `json:"bound_with"` TimeStart pgtype.Int4 `json:"time_start"` TimeEnd pgtype.Int4 `json:"time_end"` + ReplayIds []pgtype.UUID `json:"replay_ids"` } func (q *Queries) GetEntityGeometriesByPairs(ctx context.Context, arg GetEntityGeometriesByPairsParams) ([]GetEntityGeometriesByPairsRow, error) { @@ -248,6 +255,7 @@ func (q *Queries) GetEntityGeometriesByPairs(ctx context.Context, arg GetEntityG &i.BoundWith, &i.TimeStart, &i.TimeEnd, + &i.ReplayIds, ); err != nil { return nil, err } @@ -261,14 +269,20 @@ func (q *Queries) GetEntityGeometriesByPairs(ctx context.Context, arg GetEntityG const getGeometriesByBoundWith = `-- name: GetGeometriesByBoundWith :many SELECT - id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id, - ST_XMin(bbox)::float8 as min_lng, - ST_YMin(bbox)::float8 as min_lat, - ST_XMax(bbox)::float8 as max_lng, - ST_YMax(bbox)::float8 as max_lat, - is_deleted, created_at, updated_at + geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id, + ST_XMin(geometries.bbox)::float8 as min_lng, + ST_YMin(geometries.bbox)::float8 as min_lat, + ST_XMax(geometries.bbox)::float8 as max_lng, + ST_YMax(geometries.bbox)::float8 as max_lat, + geometries.is_deleted, geometries.created_at, geometries.updated_at, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = geometries.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM geometries -WHERE bound_with = $1 AND is_deleted = false +WHERE geometries.bound_with = $1 AND geometries.is_deleted = false ` type GetGeometriesByBoundWithRow struct { @@ -286,6 +300,7 @@ type GetGeometriesByBoundWithRow struct { IsDeleted bool `json:"is_deleted"` CreatedAt pgtype.Timestamptz `json:"created_at"` UpdatedAt pgtype.Timestamptz `json:"updated_at"` + ReplayIds []pgtype.UUID `json:"replay_ids"` } func (q *Queries) GetGeometriesByBoundWith(ctx context.Context, boundWith pgtype.UUID) ([]GetGeometriesByBoundWithRow, error) { @@ -312,6 +327,7 @@ func (q *Queries) GetGeometriesByBoundWith(ctx context.Context, boundWith pgtype &i.IsDeleted, &i.CreatedAt, &i.UpdatedAt, + &i.ReplayIds, ); err != nil { return nil, err } @@ -325,14 +341,20 @@ func (q *Queries) GetGeometriesByBoundWith(ctx context.Context, boundWith pgtype const getGeometriesByIDs = `-- name: GetGeometriesByIDs :many SELECT - id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id, - ST_XMin(bbox)::float8 as min_lng, - ST_YMin(bbox)::float8 as min_lat, - ST_XMax(bbox)::float8 as max_lng, - ST_YMax(bbox)::float8 as max_lat, - is_deleted, created_at, updated_at + geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id, + ST_XMin(geometries.bbox)::float8 as min_lng, + ST_YMin(geometries.bbox)::float8 as min_lat, + ST_XMax(geometries.bbox)::float8 as max_lng, + ST_YMax(geometries.bbox)::float8 as max_lat, + geometries.is_deleted, geometries.created_at, geometries.updated_at, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = geometries.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM geometries -WHERE id = ANY($1::uuid[]) AND is_deleted = false +WHERE geometries.id = ANY($1::uuid[]) AND geometries.is_deleted = false ` type GetGeometriesByIDsRow struct { @@ -350,6 +372,7 @@ type GetGeometriesByIDsRow struct { IsDeleted bool `json:"is_deleted"` CreatedAt pgtype.Timestamptz `json:"created_at"` UpdatedAt pgtype.Timestamptz `json:"updated_at"` + ReplayIds []pgtype.UUID `json:"replay_ids"` } func (q *Queries) GetGeometriesByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]GetGeometriesByIDsRow, error) { @@ -376,6 +399,7 @@ func (q *Queries) GetGeometriesByIDs(ctx context.Context, dollar_1 []pgtype.UUID &i.IsDeleted, &i.CreatedAt, &i.UpdatedAt, + &i.ReplayIds, ); err != nil { return nil, err } @@ -389,14 +413,20 @@ func (q *Queries) GetGeometriesByIDs(ctx context.Context, dollar_1 []pgtype.UUID const getGeometriesByProjectId = `-- name: GetGeometriesByProjectId :many SELECT - id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id, - ST_XMin(bbox)::float8 as min_lng, - ST_YMin(bbox)::float8 as min_lat, - ST_XMax(bbox)::float8 as max_lng, - ST_YMax(bbox)::float8 as max_lat, - is_deleted, created_at, updated_at + geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id, + ST_XMin(geometries.bbox)::float8 as min_lng, + ST_YMin(geometries.bbox)::float8 as min_lat, + ST_XMax(geometries.bbox)::float8 as max_lng, + ST_YMax(geometries.bbox)::float8 as max_lat, + geometries.is_deleted, geometries.created_at, geometries.updated_at, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = geometries.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM geometries -WHERE project_id = $1 AND is_deleted = false +WHERE geometries.project_id = $1 AND geometries.is_deleted = false ` type GetGeometriesByProjectIdRow struct { @@ -414,6 +444,7 @@ type GetGeometriesByProjectIdRow struct { IsDeleted bool `json:"is_deleted"` CreatedAt pgtype.Timestamptz `json:"created_at"` UpdatedAt pgtype.Timestamptz `json:"updated_at"` + ReplayIds []pgtype.UUID `json:"replay_ids"` } func (q *Queries) GetGeometriesByProjectId(ctx context.Context, projectID pgtype.UUID) ([]GetGeometriesByProjectIdRow, error) { @@ -440,6 +471,7 @@ func (q *Queries) GetGeometriesByProjectId(ctx context.Context, projectID pgtype &i.IsDeleted, &i.CreatedAt, &i.UpdatedAt, + &i.ReplayIds, ); err != nil { return nil, err } @@ -452,11 +484,17 @@ func (q *Queries) GetGeometriesByProjectId(ctx context.Context, projectID pgtype } const getGeometryById = `-- name: GetGeometryById :one -SELECT id, geo_type, draw_geometry, bound_with, time_start, time_end, project_id, - ST_XMin(bbox)::float8 as min_lng, ST_YMin(bbox)::float8 as min_lat, ST_XMax(bbox)::float8 as max_lng, ST_YMax(bbox)::float8 as max_lat, - is_deleted, created_at, updated_at +SELECT geometries.id, geometries.geo_type, geometries.draw_geometry, geometries.bound_with, geometries.time_start, geometries.time_end, geometries.project_id, + ST_XMin(geometries.bbox)::float8 as min_lng, ST_YMin(geometries.bbox)::float8 as min_lat, ST_XMax(geometries.bbox)::float8 as max_lng, ST_YMax(geometries.bbox)::float8 as max_lat, + geometries.is_deleted, geometries.created_at, geometries.updated_at, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = geometries.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM geometries -WHERE id = $1 AND is_deleted = false +WHERE geometries.id = $1 AND geometries.is_deleted = false ` type GetGeometryByIdRow struct { @@ -474,6 +512,7 @@ type GetGeometryByIdRow struct { IsDeleted bool `json:"is_deleted"` CreatedAt pgtype.Timestamptz `json:"created_at"` UpdatedAt pgtype.Timestamptz `json:"updated_at"` + ReplayIds []pgtype.UUID `json:"replay_ids"` } func (q *Queries) GetGeometryById(ctx context.Context, id pgtype.UUID) (GetGeometryByIdRow, error) { @@ -494,6 +533,7 @@ func (q *Queries) GetGeometryById(ctx context.Context, id pgtype.UUID) (GetGeome &i.IsDeleted, &i.CreatedAt, &i.UpdatedAt, + &i.ReplayIds, ) return i, err } @@ -505,7 +545,13 @@ SELECT ST_YMin(g.bbox)::float8 as min_lat, ST_XMax(g.bbox)::float8 as max_lng, ST_YMax(g.bbox)::float8 as max_lat, - g.is_deleted, g.created_at, g.updated_at + g.is_deleted, g.created_at, g.updated_at, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = g.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM geometries g WHERE g.is_deleted = false AND ($1::uuid IS NULL OR g.project_id = $1::uuid) @@ -576,6 +622,7 @@ type SearchGeometriesRow struct { IsDeleted bool `json:"is_deleted"` CreatedAt pgtype.Timestamptz `json:"created_at"` UpdatedAt pgtype.Timestamptz `json:"updated_at"` + ReplayIds []pgtype.UUID `json:"replay_ids"` } func (q *Queries) SearchGeometries(ctx context.Context, arg SearchGeometriesParams) ([]SearchGeometriesRow, error) { @@ -613,6 +660,7 @@ func (q *Queries) SearchGeometries(ctx context.Context, arg SearchGeometriesPara &i.IsDeleted, &i.CreatedAt, &i.UpdatedAt, + &i.ReplayIds, ); err != nil { return nil, err } @@ -646,7 +694,13 @@ SELECT g.draw_geometry, g.bound_with, g.time_start, - g.time_end + g.time_end, + COALESCE( + (SELECT ARRAY_AGG(br.id) FROM battle_replays br + WHERE br.geometry_id = g.id + AND br.is_deleted = false), + '{}'::uuid[] + )::uuid[] AS replay_ids FROM matched_entities me LEFT JOIN entity_geometries eg ON eg.entity_id = me.id @@ -663,15 +717,16 @@ type SearchGeometriesByEntityNameParams struct { } type SearchGeometriesByEntityNameRow struct { - EntityID pgtype.UUID `json:"entity_id"` - EntityName string `json:"entity_name"` - EntityDescription pgtype.Text `json:"entity_description"` - GeometryID pgtype.UUID `json:"geometry_id"` - GeoType pgtype.Int2 `json:"geo_type"` - DrawGeometry []byte `json:"draw_geometry"` - BoundWith pgtype.UUID `json:"bound_with"` - TimeStart pgtype.Int4 `json:"time_start"` - TimeEnd pgtype.Int4 `json:"time_end"` + EntityID pgtype.UUID `json:"entity_id"` + EntityName string `json:"entity_name"` + EntityDescription pgtype.Text `json:"entity_description"` + GeometryID pgtype.UUID `json:"geometry_id"` + GeoType pgtype.Int2 `json:"geo_type"` + DrawGeometry []byte `json:"draw_geometry"` + BoundWith pgtype.UUID `json:"bound_with"` + TimeStart pgtype.Int4 `json:"time_start"` + TimeEnd pgtype.Int4 `json:"time_end"` + ReplayIds []pgtype.UUID `json:"replay_ids"` } func (q *Queries) SearchGeometriesByEntityName(ctx context.Context, arg SearchGeometriesByEntityNameParams) ([]SearchGeometriesByEntityNameRow, error) { @@ -693,6 +748,7 @@ func (q *Queries) SearchGeometriesByEntityName(ctx context.Context, arg SearchGe &i.BoundWith, &i.TimeStart, &i.TimeEnd, + &i.ReplayIds, ); err != nil { return nil, err } diff --git a/internal/models/geometry.go b/internal/models/geometry.go index a4349cb..f3e1dbd 100644 --- a/internal/models/geometry.go +++ b/internal/models/geometry.go @@ -16,6 +16,7 @@ type GeometryEntity struct { Bbox *response.Bbox `json:"bbox"` ProjectID string `json:"project_id"` IsDeleted bool `json:"is_deleted"` + ReplayIDs []string `json:"replay_ids"` CreatedAt *time.Time `json:"created_at"` UpdatedAt *time.Time `json:"updated_at"` } @@ -30,6 +31,7 @@ type EntityGeometriesSearchEntity struct { BoundWith *string `json:"bound_with,omitempty"` TimeStart *int32 `json:"time_start,omitempty"` TimeEnd *int32 `json:"time_end,omitempty"` + ReplayIDs []string `json:"replay_ids,omitempty"` } func (g *GeometryEntity) ToResponse() *response.GeometryResponse { @@ -46,6 +48,7 @@ func (g *GeometryEntity) ToResponse() *response.GeometryResponse { Bbox: g.Bbox, ProjectID: g.ProjectID, IsDeleted: g.IsDeleted, + ReplayIDs: g.ReplayIDs, CreatedAt: g.CreatedAt, UpdatedAt: g.UpdatedAt, } diff --git a/internal/repositories/battleReplayRepository.go b/internal/repositories/battleReplayRepository.go index b068b02..c7359de 100644 --- a/internal/repositories/battleReplayRepository.go +++ b/internal/repositories/battleReplayRepository.go @@ -253,6 +253,7 @@ func (r *battleReplayRepository) Create(ctx context.Context, params sqlc.CreateB _ = r.c.Del(ctx, cache.Key("battle_replay:project", entity.ProjectID)) _ = r.c.Del(ctx, cache.Key("battle_replay:geometry", entity.GeometryID)) + _ = r.c.Del(ctx, cache.Key("geometry:id", entity.GeometryID)) return entity, nil } @@ -265,10 +266,16 @@ func (r *battleReplayRepository) Update(ctx context.Context, params sqlc.UpdateB entity := r.rowToEntity(row) _ = r.c.Del(ctx, cache.Key("battle_replay:id", entity.ID)) + _ = r.c.Del(ctx, cache.Key("battle_replay:geometry", entity.GeometryID)) + _ = r.c.Del(ctx, cache.Key("geometry:id", entity.GeometryID)) return entity, nil } func (r *battleReplayRepository) Delete(ctx context.Context, id pgtype.UUID) error { + if item, err := r.GetByID(ctx, id); err == nil && item != nil { + _ = r.c.Del(ctx, cache.Key("geometry:id", item.GeometryID)) + _ = r.c.Del(ctx, cache.Key("battle_replay:geometry", item.GeometryID)) + } err := r.q.DeleteBattleReplay(ctx, id) if err != nil { return err @@ -278,6 +285,20 @@ func (r *battleReplayRepository) Delete(ctx context.Context, id pgtype.UUID) err } func (r *battleReplayRepository) DeleteByIDs(ctx context.Context, ids []pgtype.UUID) error { + if len(ids) > 0 { + strIDs := make([]string, len(ids)) + for i, id := range ids { + strIDs[i] = convert.UUIDToString(id) + } + if items, err := r.GetByIDs(ctx, strIDs); err == nil { + for _, item := range items { + if item != nil { + _ = r.c.Del(ctx, cache.Key("geometry:id", item.GeometryID)) + _ = r.c.Del(ctx, cache.Key("battle_replay:geometry", item.GeometryID)) + } + } + } + } err := r.q.DeleteBattleReplaysByIDs(ctx, ids) if err != nil { return err diff --git a/internal/repositories/geometryRepository.go b/internal/repositories/geometryRepository.go index d3d50b6..1b00b41 100644 --- a/internal/repositories/geometryRepository.go +++ b/internal/repositories/geometryRepository.go @@ -105,6 +105,7 @@ func (r *geometryRepository) getByIDsWithFallback(ctx context.Context, ids []str }, ProjectID: convert.UUIDToString(row.ProjectID), IsDeleted: row.IsDeleted, + ReplayIDs: convert.ListUUIDToString(row.ReplayIds), CreatedAt: convert.TimeToPtr(row.CreatedAt), UpdatedAt: convert.TimeToPtr(row.UpdatedAt), } @@ -167,6 +168,7 @@ func (r *geometryRepository) GetByID(ctx context.Context, id pgtype.UUID) (*mode }, ProjectID: convert.UUIDToString(row.ProjectID), IsDeleted: row.IsDeleted, + ReplayIDs: convert.ListUUIDToString(row.ReplayIds), CreatedAt: convert.TimeToPtr(row.CreatedAt), UpdatedAt: convert.TimeToPtr(row.UpdatedAt), } @@ -210,6 +212,7 @@ func (r *geometryRepository) Search(ctx context.Context, params sqlc.SearchGeome }, ProjectID: convert.UUIDToString(row.ProjectID), IsDeleted: row.IsDeleted, + ReplayIDs: convert.ListUUIDToString(row.ReplayIds), CreatedAt: convert.TimeToPtr(row.CreatedAt), UpdatedAt: convert.TimeToPtr(row.UpdatedAt), } @@ -342,6 +345,7 @@ func (r *geometryRepository) GetByProjectID(ctx context.Context, projectID pgtyp }, ProjectID: convert.UUIDToString(row.ProjectID), IsDeleted: row.IsDeleted, + ReplayIDs: convert.ListUUIDToString(row.ReplayIds), CreatedAt: convert.TimeToPtr(row.CreatedAt), UpdatedAt: convert.TimeToPtr(row.UpdatedAt), } @@ -394,6 +398,7 @@ func (r *geometryRepository) GetGeometriesByBoundWith(ctx context.Context, bound }, ProjectID: convert.UUIDToString(row.ProjectID), IsDeleted: row.IsDeleted, + ReplayIDs: convert.ListUUIDToString(row.ReplayIds), CreatedAt: convert.TimeToPtr(row.CreatedAt), UpdatedAt: convert.TimeToPtr(row.UpdatedAt), } @@ -485,6 +490,7 @@ func (r *geometryRepository) getSearchByIDsWithFallback(ctx context.Context, pai BoundWith: convert.UUIDToStringPtr(row.BoundWith), TimeStart: convert.Int4ToPtr(row.TimeStart), TimeEnd: convert.Int4ToPtr(row.TimeEnd), + ReplayIDs: convert.ListUUIDToString(row.ReplayIds), } key := cache.Key(item.EntityID, item.GeometryID) dbMap[key] = item @@ -544,6 +550,7 @@ func (r *geometryRepository) SearchByEntityName(ctx context.Context, params sqlc BoundWith: convert.UUIDToStringPtr(row.BoundWith), TimeStart: convert.Int4ToPtr(row.TimeStart), TimeEnd: convert.Int4ToPtr(row.TimeEnd), + ReplayIDs: convert.ListUUIDToString(row.ReplayIds), } pair := cache.Key(item.EntityID, item.GeometryID) geometries = append(geometries, item) diff --git a/internal/services/geometryService.go b/internal/services/geometryService.go index 6e9aeb2..208ecea 100644 --- a/internal/services/geometryService.go +++ b/internal/services/geometryService.go @@ -163,6 +163,7 @@ func (s *geometryService) SearchGeometriesByEntityName( BoundWith: row.BoundWith, TimeStart: row.TimeStart, TimeEnd: row.TimeEnd, + ReplayIDs: row.ReplayIDs, }) }