From e3ca50c4aed1f453330520c63204df56aa8c00eb Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 10 Mar 2025 22:15:59 +0800 Subject: [PATCH] :sparkles: Update usage grpc call --- pkg/internal/grpc/attachment.go | 14 ++ pkg/internal/models/attachments.go | 5 +- pkg/internal/services/attachments.go | 10 ++ pkg/proto/attachment.pb.go | 231 ++++++++++++++++++++------- pkg/proto/attachment.proto | 10 ++ pkg/proto/attachment_grpc.pb.go | 38 +++++ 6 files changed, 248 insertions(+), 60 deletions(-) diff --git a/pkg/internal/grpc/attachment.go b/pkg/internal/grpc/attachment.go index 4899c16..f7be0fc 100644 --- a/pkg/internal/grpc/attachment.go +++ b/pkg/internal/grpc/attachment.go @@ -5,6 +5,7 @@ import ( "git.solsynth.dev/hypernet/paperclip/pkg/internal/database" "git.solsynth.dev/hypernet/paperclip/pkg/internal/models" + "git.solsynth.dev/hypernet/paperclip/pkg/internal/services" "git.solsynth.dev/hypernet/paperclip/pkg/proto" "github.com/rs/zerolog/log" "github.com/samber/lo" @@ -91,6 +92,19 @@ func (v *Server) UpdateVisibility(ctx context.Context, request *proto.UpdateVisi }, nil } +func (v *Server) UpdateUsage(ctx context.Context, request *proto.UpdateUsageRequest) (*proto.UpdateUsageResponse, error) { + id := lo.Map(request.GetId(), func(item uint64, _ int) uint { + return uint(item) + }) + if rows, err := services.CountAttachmentUsage(id, int(request.GetDelta())); err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } else { + return &proto.UpdateUsageResponse{ + Count: int32(rows), + }, nil + } +} + func (v *Server) DeleteAttachment(ctx context.Context, request *proto.DeleteAttachmentRequest) (*proto.DeleteAttachmentResponse, error) { tx := database.C if len(request.Id) == 0 && len(request.Rid) == 0 { diff --git a/pkg/internal/models/attachments.go b/pkg/internal/models/attachments.go index 2e628fd..0959e98 100644 --- a/pkg/internal/models/attachments.go +++ b/pkg/internal/models/attachments.go @@ -3,10 +3,11 @@ package models import ( "context" "fmt" - "git.solsynth.dev/hypernet/paperclip/pkg/proto" "strconv" "time" + "git.solsynth.dev/hypernet/paperclip/pkg/proto" + "git.solsynth.dev/hypernet/nexus/pkg/nex/cruda" "github.com/eko/gocache/lib/v4/cache" "github.com/eko/gocache/lib/v4/marshaler" @@ -56,6 +57,8 @@ type Attachment struct { IsSelfRef bool `json:"is_self_ref"` IsIndexable bool `json:"is_indexable"` // Show this attachment in the public directory api or not + // Count the usage of this attachment across all services + // If this number remain 0, it will be deleted during the maintenance UsedCount int `json:"used_count"` Thumbnail *Attachment `json:"thumbnail"` diff --git a/pkg/internal/services/attachments.go b/pkg/internal/services/attachments.go index f0b0db5..66e725a 100644 --- a/pkg/internal/services/attachments.go +++ b/pkg/internal/services/attachments.go @@ -238,3 +238,13 @@ func DeleteAttachment(item models.Attachment, txs ...*gorm.DB) error { return nil } + +func CountAttachmentUsage(id []uint, delta int) (int64, error) { + if tx := database.C.Model(&models.Attachment{}). + Where("id IN ?", id). + Update("used_count", gorm.Expr("used_count + ?", delta)); tx.Error != nil { + return tx.RowsAffected, tx.Error + } else { + return tx.RowsAffected, nil + } +} diff --git a/pkg/proto/attachment.pb.go b/pkg/proto/attachment.pb.go index cd5aa45..2642378 100644 --- a/pkg/proto/attachment.pb.go +++ b/pkg/proto/attachment.pb.go @@ -447,6 +447,104 @@ func (x *UpdateVisibilityResponse) GetCount() int32 { return 0 } +type UpdateUsageRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id []uint64 `protobuf:"varint,1,rep,packed,name=id,proto3" json:"id,omitempty"` + Delta int64 `protobuf:"varint,2,opt,name=delta,proto3" json:"delta,omitempty"` +} + +func (x *UpdateUsageRequest) Reset() { + *x = UpdateUsageRequest{} + mi := &file_attachment_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdateUsageRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateUsageRequest) ProtoMessage() {} + +func (x *UpdateUsageRequest) ProtoReflect() protoreflect.Message { + mi := &file_attachment_proto_msgTypes[7] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateUsageRequest.ProtoReflect.Descriptor instead. +func (*UpdateUsageRequest) Descriptor() ([]byte, []int) { + return file_attachment_proto_rawDescGZIP(), []int{7} +} + +func (x *UpdateUsageRequest) GetId() []uint64 { + if x != nil { + return x.Id + } + return nil +} + +func (x *UpdateUsageRequest) GetDelta() int64 { + if x != nil { + return x.Delta + } + return 0 +} + +type UpdateUsageResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Count int32 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` +} + +func (x *UpdateUsageResponse) Reset() { + *x = UpdateUsageResponse{} + mi := &file_attachment_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdateUsageResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateUsageResponse) ProtoMessage() {} + +func (x *UpdateUsageResponse) ProtoReflect() protoreflect.Message { + mi := &file_attachment_proto_msgTypes[8] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateUsageResponse.ProtoReflect.Descriptor instead. +func (*UpdateUsageResponse) Descriptor() ([]byte, []int) { + return file_attachment_proto_rawDescGZIP(), []int{8} +} + +func (x *UpdateUsageResponse) GetCount() int32 { + if x != nil { + return x.Count + } + return 0 +} + type DeleteAttachmentRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -459,7 +557,7 @@ type DeleteAttachmentRequest struct { func (x *DeleteAttachmentRequest) Reset() { *x = DeleteAttachmentRequest{} - mi := &file_attachment_proto_msgTypes[7] + mi := &file_attachment_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -471,7 +569,7 @@ func (x *DeleteAttachmentRequest) String() string { func (*DeleteAttachmentRequest) ProtoMessage() {} func (x *DeleteAttachmentRequest) ProtoReflect() protoreflect.Message { - mi := &file_attachment_proto_msgTypes[7] + mi := &file_attachment_proto_msgTypes[9] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -484,7 +582,7 @@ func (x *DeleteAttachmentRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteAttachmentRequest.ProtoReflect.Descriptor instead. func (*DeleteAttachmentRequest) Descriptor() ([]byte, []int) { - return file_attachment_proto_rawDescGZIP(), []int{7} + return file_attachment_proto_rawDescGZIP(), []int{9} } func (x *DeleteAttachmentRequest) GetId() []uint64 { @@ -518,7 +616,7 @@ type DeleteAttachmentResponse struct { func (x *DeleteAttachmentResponse) Reset() { *x = DeleteAttachmentResponse{} - mi := &file_attachment_proto_msgTypes[8] + mi := &file_attachment_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -530,7 +628,7 @@ func (x *DeleteAttachmentResponse) String() string { func (*DeleteAttachmentResponse) ProtoMessage() {} func (x *DeleteAttachmentResponse) ProtoReflect() protoreflect.Message { - mi := &file_attachment_proto_msgTypes[8] + mi := &file_attachment_proto_msgTypes[10] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -543,7 +641,7 @@ func (x *DeleteAttachmentResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteAttachmentResponse.ProtoReflect.Descriptor instead. func (*DeleteAttachmentResponse) Descriptor() ([]byte, []int) { - return file_attachment_proto_rawDescGZIP(), []int{8} + return file_attachment_proto_rawDescGZIP(), []int{10} } func (x *DeleteAttachmentResponse) GetCount() int32 { @@ -606,40 +704,51 @@ var file_attachment_proto_rawDesc = []byte{ 0x08, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x22, 0x30, 0x0a, 0x18, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x56, 0x69, 0x73, 0x69, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x65, 0x0a, 0x17, 0x44, - 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x03, - 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x69, 0x64, 0x18, 0x02, 0x20, - 0x03, 0x28, 0x09, 0x52, 0x03, 0x72, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, - 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x48, 0x00, 0x52, 0x06, 0x75, 0x73, 0x65, - 0x72, 0x49, 0x64, 0x88, 0x01, 0x01, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, - 0x69, 0x64, 0x22, 0x30, 0x0a, 0x18, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x74, 0x74, 0x61, - 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x3a, 0x0a, 0x12, 0x55, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x03, 0x28, 0x04, 0x52, 0x02, 0x69, + 0x64, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x65, 0x6c, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x05, 0x64, 0x65, 0x6c, 0x74, 0x61, 0x22, 0x2b, 0x0a, 0x13, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x32, 0xe0, 0x02, 0x0a, 0x11, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, - 0x65, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x4c, 0x0a, 0x0d, 0x47, 0x65, - 0x74, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1b, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, - 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x47, 0x65, 0x74, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4f, 0x0a, 0x0e, 0x4c, 0x69, 0x73, 0x74, - 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1c, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, - 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x55, 0x0a, 0x10, 0x55, 0x70, 0x64, - 0x61, 0x74, 0x65, 0x56, 0x69, 0x73, 0x69, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x12, 0x1e, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x56, 0x69, 0x73, 0x69, - 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x56, 0x69, 0x73, 0x69, - 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, - 0x12, 0x55, 0x0a, 0x10, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, - 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, 0x6c, - 0x65, 0x74, 0x65, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, 0x6c, - 0x65, 0x74, 0x65, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x65, 0x0a, 0x17, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x74, + 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x03, 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x12, + 0x10, 0x0a, 0x03, 0x72, 0x69, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x03, 0x72, 0x69, + 0x64, 0x12, 0x1c, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x04, 0x48, 0x00, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x88, 0x01, 0x01, 0x42, + 0x0a, 0x0a, 0x08, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x22, 0x30, 0x0a, 0x18, 0x44, + 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x32, 0xa8, 0x03, + 0x0a, 0x11, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x4c, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, + 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, + 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x1c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x74, 0x74, + 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x4f, 0x0a, 0x0e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, + 0x65, 0x6e, 0x74, 0x12, 0x1c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4c, 0x69, 0x73, 0x74, + 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x74, + 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x00, 0x12, 0x55, 0x0a, 0x10, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x56, 0x69, 0x73, 0x69, + 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x12, 0x1e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x55, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x56, 0x69, 0x73, 0x69, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x55, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x56, 0x69, 0x73, 0x69, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x0b, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x55, 0x73, 0x61, 0x67, 0x65, 0x12, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x55, 0x0a, 0x10, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x74, 0x74, 0x61, 0x63, + 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, + 0x6c, 0x65, 0x74, 0x65, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x65, + 0x6c, 0x65, 0x74, 0x65, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -654,7 +763,7 @@ func file_attachment_proto_rawDescGZIP() []byte { return file_attachment_proto_rawDescData } -var file_attachment_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_attachment_proto_msgTypes = make([]protoimpl.MessageInfo, 11) var file_attachment_proto_goTypes = []any{ (*AttachmentInfo)(nil), // 0: proto.AttachmentInfo (*GetAttachmentRequest)(nil), // 1: proto.GetAttachmentRequest @@ -663,25 +772,29 @@ var file_attachment_proto_goTypes = []any{ (*ListAttachmentResponse)(nil), // 4: proto.ListAttachmentResponse (*UpdateVisibilityRequest)(nil), // 5: proto.UpdateVisibilityRequest (*UpdateVisibilityResponse)(nil), // 6: proto.UpdateVisibilityResponse - (*DeleteAttachmentRequest)(nil), // 7: proto.DeleteAttachmentRequest - (*DeleteAttachmentResponse)(nil), // 8: proto.DeleteAttachmentResponse + (*UpdateUsageRequest)(nil), // 7: proto.UpdateUsageRequest + (*UpdateUsageResponse)(nil), // 8: proto.UpdateUsageResponse + (*DeleteAttachmentRequest)(nil), // 9: proto.DeleteAttachmentRequest + (*DeleteAttachmentResponse)(nil), // 10: proto.DeleteAttachmentResponse } var file_attachment_proto_depIdxs = []int32{ - 0, // 0: proto.GetAttachmentResponse.attachment:type_name -> proto.AttachmentInfo - 0, // 1: proto.ListAttachmentResponse.attachments:type_name -> proto.AttachmentInfo - 1, // 2: proto.AttachmentService.GetAttachment:input_type -> proto.GetAttachmentRequest - 3, // 3: proto.AttachmentService.ListAttachment:input_type -> proto.ListAttachmentRequest - 5, // 4: proto.AttachmentService.UpdateVisibility:input_type -> proto.UpdateVisibilityRequest - 7, // 5: proto.AttachmentService.DeleteAttachment:input_type -> proto.DeleteAttachmentRequest - 2, // 6: proto.AttachmentService.GetAttachment:output_type -> proto.GetAttachmentResponse - 4, // 7: proto.AttachmentService.ListAttachment:output_type -> proto.ListAttachmentResponse - 6, // 8: proto.AttachmentService.UpdateVisibility:output_type -> proto.UpdateVisibilityResponse - 8, // 9: proto.AttachmentService.DeleteAttachment:output_type -> proto.DeleteAttachmentResponse - 6, // [6:10] is the sub-list for method output_type - 2, // [2:6] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 0, // 0: proto.GetAttachmentResponse.attachment:type_name -> proto.AttachmentInfo + 0, // 1: proto.ListAttachmentResponse.attachments:type_name -> proto.AttachmentInfo + 1, // 2: proto.AttachmentService.GetAttachment:input_type -> proto.GetAttachmentRequest + 3, // 3: proto.AttachmentService.ListAttachment:input_type -> proto.ListAttachmentRequest + 5, // 4: proto.AttachmentService.UpdateVisibility:input_type -> proto.UpdateVisibilityRequest + 7, // 5: proto.AttachmentService.UpdateUsage:input_type -> proto.UpdateUsageRequest + 9, // 6: proto.AttachmentService.DeleteAttachment:input_type -> proto.DeleteAttachmentRequest + 2, // 7: proto.AttachmentService.GetAttachment:output_type -> proto.GetAttachmentResponse + 4, // 8: proto.AttachmentService.ListAttachment:output_type -> proto.ListAttachmentResponse + 6, // 9: proto.AttachmentService.UpdateVisibility:output_type -> proto.UpdateVisibilityResponse + 8, // 10: proto.AttachmentService.UpdateUsage:output_type -> proto.UpdateUsageResponse + 10, // 11: proto.AttachmentService.DeleteAttachment:output_type -> proto.DeleteAttachmentResponse + 7, // [7:12] is the sub-list for method output_type + 2, // [2:7] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_attachment_proto_init() } @@ -693,14 +806,14 @@ func file_attachment_proto_init() { file_attachment_proto_msgTypes[2].OneofWrappers = []any{} file_attachment_proto_msgTypes[3].OneofWrappers = []any{} file_attachment_proto_msgTypes[5].OneofWrappers = []any{} - file_attachment_proto_msgTypes[7].OneofWrappers = []any{} + file_attachment_proto_msgTypes[9].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_attachment_proto_rawDesc, NumEnums: 0, - NumMessages: 9, + NumMessages: 11, NumExtensions: 0, NumServices: 1, }, diff --git a/pkg/proto/attachment.proto b/pkg/proto/attachment.proto index 8eeffdc..0ab8c6a 100644 --- a/pkg/proto/attachment.proto +++ b/pkg/proto/attachment.proto @@ -8,6 +8,7 @@ service AttachmentService { rpc GetAttachment(GetAttachmentRequest) returns (GetAttachmentResponse) {} rpc ListAttachment(ListAttachmentRequest) returns (ListAttachmentResponse) {} rpc UpdateVisibility(UpdateVisibilityRequest) returns (UpdateVisibilityResponse) {} + rpc UpdateUsage(UpdateUsageRequest) returns (UpdateUsageResponse) {} rpc DeleteAttachment(DeleteAttachmentRequest) returns (DeleteAttachmentResponse) {} } @@ -53,6 +54,15 @@ message UpdateVisibilityResponse { int32 count = 1; } +message UpdateUsageRequest { + repeated uint64 id = 1; + int64 delta = 2; +} + +message UpdateUsageResponse { + int32 count = 1; +} + message DeleteAttachmentRequest { repeated uint64 id = 1; repeated string rid = 2; diff --git a/pkg/proto/attachment_grpc.pb.go b/pkg/proto/attachment_grpc.pb.go index b46edae..ac8db18 100644 --- a/pkg/proto/attachment_grpc.pb.go +++ b/pkg/proto/attachment_grpc.pb.go @@ -22,6 +22,7 @@ const ( AttachmentService_GetAttachment_FullMethodName = "/proto.AttachmentService/GetAttachment" AttachmentService_ListAttachment_FullMethodName = "/proto.AttachmentService/ListAttachment" AttachmentService_UpdateVisibility_FullMethodName = "/proto.AttachmentService/UpdateVisibility" + AttachmentService_UpdateUsage_FullMethodName = "/proto.AttachmentService/UpdateUsage" AttachmentService_DeleteAttachment_FullMethodName = "/proto.AttachmentService/DeleteAttachment" ) @@ -32,6 +33,7 @@ type AttachmentServiceClient interface { GetAttachment(ctx context.Context, in *GetAttachmentRequest, opts ...grpc.CallOption) (*GetAttachmentResponse, error) ListAttachment(ctx context.Context, in *ListAttachmentRequest, opts ...grpc.CallOption) (*ListAttachmentResponse, error) UpdateVisibility(ctx context.Context, in *UpdateVisibilityRequest, opts ...grpc.CallOption) (*UpdateVisibilityResponse, error) + UpdateUsage(ctx context.Context, in *UpdateUsageRequest, opts ...grpc.CallOption) (*UpdateUsageResponse, error) DeleteAttachment(ctx context.Context, in *DeleteAttachmentRequest, opts ...grpc.CallOption) (*DeleteAttachmentResponse, error) } @@ -73,6 +75,16 @@ func (c *attachmentServiceClient) UpdateVisibility(ctx context.Context, in *Upda return out, nil } +func (c *attachmentServiceClient) UpdateUsage(ctx context.Context, in *UpdateUsageRequest, opts ...grpc.CallOption) (*UpdateUsageResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(UpdateUsageResponse) + err := c.cc.Invoke(ctx, AttachmentService_UpdateUsage_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *attachmentServiceClient) DeleteAttachment(ctx context.Context, in *DeleteAttachmentRequest, opts ...grpc.CallOption) (*DeleteAttachmentResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(DeleteAttachmentResponse) @@ -90,6 +102,7 @@ type AttachmentServiceServer interface { GetAttachment(context.Context, *GetAttachmentRequest) (*GetAttachmentResponse, error) ListAttachment(context.Context, *ListAttachmentRequest) (*ListAttachmentResponse, error) UpdateVisibility(context.Context, *UpdateVisibilityRequest) (*UpdateVisibilityResponse, error) + UpdateUsage(context.Context, *UpdateUsageRequest) (*UpdateUsageResponse, error) DeleteAttachment(context.Context, *DeleteAttachmentRequest) (*DeleteAttachmentResponse, error) mustEmbedUnimplementedAttachmentServiceServer() } @@ -110,6 +123,9 @@ func (UnimplementedAttachmentServiceServer) ListAttachment(context.Context, *Lis func (UnimplementedAttachmentServiceServer) UpdateVisibility(context.Context, *UpdateVisibilityRequest) (*UpdateVisibilityResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateVisibility not implemented") } +func (UnimplementedAttachmentServiceServer) UpdateUsage(context.Context, *UpdateUsageRequest) (*UpdateUsageResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateUsage not implemented") +} func (UnimplementedAttachmentServiceServer) DeleteAttachment(context.Context, *DeleteAttachmentRequest) (*DeleteAttachmentResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method DeleteAttachment not implemented") } @@ -188,6 +204,24 @@ func _AttachmentService_UpdateVisibility_Handler(srv interface{}, ctx context.Co return interceptor(ctx, in, info, handler) } +func _AttachmentService_UpdateUsage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateUsageRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AttachmentServiceServer).UpdateUsage(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: AttachmentService_UpdateUsage_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AttachmentServiceServer).UpdateUsage(ctx, req.(*UpdateUsageRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _AttachmentService_DeleteAttachment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(DeleteAttachmentRequest) if err := dec(in); err != nil { @@ -225,6 +259,10 @@ var AttachmentService_ServiceDesc = grpc.ServiceDesc{ MethodName: "UpdateVisibility", Handler: _AttachmentService_UpdateVisibility_Handler, }, + { + MethodName: "UpdateUsage", + Handler: _AttachmentService_UpdateUsage_Handler, + }, { MethodName: "DeleteAttachment", Handler: _AttachmentService_DeleteAttachment_Handler,