Commit d11e7a3a authored by Steven's avatar Steven

chore: remove duplicated requests

parent c401a079
......@@ -51,10 +51,6 @@ service MemoService {
option (google.api.http) = {delete: "/api/v1/{name=memos/*}"};
option (google.api.method_signature) = "name";
}
// ListMemoProperties lists memo properties.
rpc ListMemoProperties(ListMemoPropertiesRequest) returns (ListMemoPropertiesResponse) {
option (google.api.http) = {get: "/api/v1/{name=memos/*}/properties"};
}
// RebuildMemoProperty rebuilds a memo property.
rpc RebuildMemoProperty(RebuildMemoPropertyRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
......@@ -62,10 +58,6 @@ service MemoService {
body: "*"
};
}
// ListMemoTags lists tags for a memo.
rpc ListMemoTags(ListMemoTagsRequest) returns (ListMemoTagsResponse) {
option (google.api.http) = {get: "/api/v1/{parent=memos/*}/tags"};
}
// RenameMemoTag renames a tag for a memo.
rpc RenameMemoTag(RenameMemoTagRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
......@@ -219,6 +211,16 @@ message CreateMemoRequest {
optional Location location = 5;
}
enum MemoView {
MEMO_VIEW_UNSPECIFIED = 0;
// The full view of the memo. Includes all fields.
MEMO_VIEW_FULL = 1;
// The metadata only view of the memo. Excludes the content/snippet fields.
MEMO_VIEW_METADATA_ONLY = 2;
}
message ListMemosRequest {
// The maximum number of memos to return.
int32 page_size = 1;
......@@ -230,6 +232,9 @@ message ListMemosRequest {
// Filter is used to filter memos returned in the list.
// Format: "creator == 'users/{uid}' && visibilities == ['PUBLIC', 'PROTECTED']"
string filter = 3;
// The view of the memo.
MemoView view = 4;
}
message ListMemosResponse {
......@@ -263,49 +268,12 @@ message DeleteMemoRequest {
string name = 1;
}
message ListMemoPropertiesRequest {
// The name of the memo.
// Format: memos/{id}. Use "memos/-" to list all properties.
string name = 1;
}
message ListMemoPropertiesResponse {
repeated MemoPropertyEntity entities = 1;
}
message MemoPropertyEntity {
// The name of the memo property.
// Format: memos/{id}/properties/{property_id}
string name = 1;
MemoProperty property = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
google.protobuf.Timestamp display_time = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
}
message RebuildMemoPropertyRequest {
// The name of the memo.
// Format: memos/{id}. Use "memos/-" to rebuild all memos.
string name = 1;
}
message ListMemoTagsRequest {
// The parent, who owns the tags.
// Format: memos/{id}. Use "memos/-" to list all tags.
string parent = 1;
// Filter is used to filter memos.
// Format: "creator == 'users/{uid}' && visibilities == ['PUBLIC', 'PROTECTED']"
string filter = 2;
}
message ListMemoTagsResponse {
// tag_amounts is the amount of tags.
// key is the tag name. e.g. "tag1".
// value is the amount of the tag.
map<string, int32> tag_amounts = 1;
}
message RenameMemoTagRequest {
// The parent, who owns the tags.
// Format: memos/{id}. Use "memos/-" to rename all tags.
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -26,9 +26,7 @@ const (
MemoService_GetMemoByUid_FullMethodName = "/memos.api.v1.MemoService/GetMemoByUid"
MemoService_UpdateMemo_FullMethodName = "/memos.api.v1.MemoService/UpdateMemo"
MemoService_DeleteMemo_FullMethodName = "/memos.api.v1.MemoService/DeleteMemo"
MemoService_ListMemoProperties_FullMethodName = "/memos.api.v1.MemoService/ListMemoProperties"
MemoService_RebuildMemoProperty_FullMethodName = "/memos.api.v1.MemoService/RebuildMemoProperty"
MemoService_ListMemoTags_FullMethodName = "/memos.api.v1.MemoService/ListMemoTags"
MemoService_RenameMemoTag_FullMethodName = "/memos.api.v1.MemoService/RenameMemoTag"
MemoService_DeleteMemoTag_FullMethodName = "/memos.api.v1.MemoService/DeleteMemoTag"
MemoService_SetMemoResources_FullMethodName = "/memos.api.v1.MemoService/SetMemoResources"
......@@ -58,12 +56,8 @@ type MemoServiceClient interface {
UpdateMemo(ctx context.Context, in *UpdateMemoRequest, opts ...grpc.CallOption) (*Memo, error)
// DeleteMemo deletes a memo.
DeleteMemo(ctx context.Context, in *DeleteMemoRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
// ListMemoProperties lists memo properties.
ListMemoProperties(ctx context.Context, in *ListMemoPropertiesRequest, opts ...grpc.CallOption) (*ListMemoPropertiesResponse, error)
// RebuildMemoProperty rebuilds a memo property.
RebuildMemoProperty(ctx context.Context, in *RebuildMemoPropertyRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
// ListMemoTags lists tags for a memo.
ListMemoTags(ctx context.Context, in *ListMemoTagsRequest, opts ...grpc.CallOption) (*ListMemoTagsResponse, error)
// RenameMemoTag renames a tag for a memo.
RenameMemoTag(ctx context.Context, in *RenameMemoTagRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
// DeleteMemoTag deletes a tag for a memo.
......@@ -156,16 +150,6 @@ func (c *memoServiceClient) DeleteMemo(ctx context.Context, in *DeleteMemoReques
return out, nil
}
func (c *memoServiceClient) ListMemoProperties(ctx context.Context, in *ListMemoPropertiesRequest, opts ...grpc.CallOption) (*ListMemoPropertiesResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(ListMemoPropertiesResponse)
err := c.cc.Invoke(ctx, MemoService_ListMemoProperties_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *memoServiceClient) RebuildMemoProperty(ctx context.Context, in *RebuildMemoPropertyRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(emptypb.Empty)
......@@ -176,16 +160,6 @@ func (c *memoServiceClient) RebuildMemoProperty(ctx context.Context, in *Rebuild
return out, nil
}
func (c *memoServiceClient) ListMemoTags(ctx context.Context, in *ListMemoTagsRequest, opts ...grpc.CallOption) (*ListMemoTagsResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(ListMemoTagsResponse)
err := c.cc.Invoke(ctx, MemoService_ListMemoTags_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *memoServiceClient) RenameMemoTag(ctx context.Context, in *RenameMemoTagRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(emptypb.Empty)
......@@ -312,12 +286,8 @@ type MemoServiceServer interface {
UpdateMemo(context.Context, *UpdateMemoRequest) (*Memo, error)
// DeleteMemo deletes a memo.
DeleteMemo(context.Context, *DeleteMemoRequest) (*emptypb.Empty, error)
// ListMemoProperties lists memo properties.
ListMemoProperties(context.Context, *ListMemoPropertiesRequest) (*ListMemoPropertiesResponse, error)
// RebuildMemoProperty rebuilds a memo property.
RebuildMemoProperty(context.Context, *RebuildMemoPropertyRequest) (*emptypb.Empty, error)
// ListMemoTags lists tags for a memo.
ListMemoTags(context.Context, *ListMemoTagsRequest) (*ListMemoTagsResponse, error)
// RenameMemoTag renames a tag for a memo.
RenameMemoTag(context.Context, *RenameMemoTagRequest) (*emptypb.Empty, error)
// DeleteMemoTag deletes a tag for a memo.
......@@ -368,15 +338,9 @@ func (UnimplementedMemoServiceServer) UpdateMemo(context.Context, *UpdateMemoReq
func (UnimplementedMemoServiceServer) DeleteMemo(context.Context, *DeleteMemoRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeleteMemo not implemented")
}
func (UnimplementedMemoServiceServer) ListMemoProperties(context.Context, *ListMemoPropertiesRequest) (*ListMemoPropertiesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListMemoProperties not implemented")
}
func (UnimplementedMemoServiceServer) RebuildMemoProperty(context.Context, *RebuildMemoPropertyRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method RebuildMemoProperty not implemented")
}
func (UnimplementedMemoServiceServer) ListMemoTags(context.Context, *ListMemoTagsRequest) (*ListMemoTagsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListMemoTags not implemented")
}
func (UnimplementedMemoServiceServer) RenameMemoTag(context.Context, *RenameMemoTagRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method RenameMemoTag not implemented")
}
......@@ -539,24 +503,6 @@ func _MemoService_DeleteMemo_Handler(srv interface{}, ctx context.Context, dec f
return interceptor(ctx, in, info, handler)
}
func _MemoService_ListMemoProperties_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListMemoPropertiesRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MemoServiceServer).ListMemoProperties(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: MemoService_ListMemoProperties_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MemoServiceServer).ListMemoProperties(ctx, req.(*ListMemoPropertiesRequest))
}
return interceptor(ctx, in, info, handler)
}
func _MemoService_RebuildMemoProperty_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(RebuildMemoPropertyRequest)
if err := dec(in); err != nil {
......@@ -575,24 +521,6 @@ func _MemoService_RebuildMemoProperty_Handler(srv interface{}, ctx context.Conte
return interceptor(ctx, in, info, handler)
}
func _MemoService_ListMemoTags_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListMemoTagsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MemoServiceServer).ListMemoTags(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: MemoService_ListMemoTags_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MemoServiceServer).ListMemoTags(ctx, req.(*ListMemoTagsRequest))
}
return interceptor(ctx, in, info, handler)
}
func _MemoService_RenameMemoTag_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(RenameMemoTagRequest)
if err := dec(in); err != nil {
......@@ -822,18 +750,10 @@ var MemoService_ServiceDesc = grpc.ServiceDesc{
MethodName: "DeleteMemo",
Handler: _MemoService_DeleteMemo_Handler,
},
{
MethodName: "ListMemoProperties",
Handler: _MemoService_ListMemoProperties_Handler,
},
{
MethodName: "RebuildMemoProperty",
Handler: _MemoService_RebuildMemoProperty_Handler,
},
{
MethodName: "ListMemoTags",
Handler: _MemoService_ListMemoTags_Handler,
},
{
MethodName: "RenameMemoTag",
Handler: _MemoService_RenameMemoTag_Handler,
......
......@@ -313,6 +313,20 @@ paths:
in: query
required: false
type: string
- name: view
description: |-
The view of the memo.
- MEMO_VIEW_FULL: The full view of the memo. Includes all fields.
- MEMO_VIEW_METADATA_ONLY: The metadata only view of the memo. Excludes the content/snippet fields.
in: query
required: false
type: string
enum:
- MEMO_VIEW_UNSPECIFIED
- MEMO_VIEW_FULL
- MEMO_VIEW_METADATA_ONLY
default: MEMO_VIEW_UNSPECIFIED
tags:
- MemoService
post:
......@@ -1253,30 +1267,6 @@ paths:
$ref: '#/definitions/v1CreateMemoRequest'
tags:
- MemoService
/api/v1/{name}/properties:
get:
summary: ListMemoProperties lists memo properties.
operationId: MemoService_ListMemoProperties
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1ListMemoPropertiesResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: |-
The name of the memo.
Format: memos/{id}. Use "memos/-" to list all properties.
in: path
required: true
type: string
pattern: memos/[^/]+
tags:
- MemoService
/api/v1/{name}/properties:rebuild:
post:
summary: RebuildMemoProperty rebuilds a memo property.
......@@ -1489,37 +1479,6 @@ paths:
pattern: users/[^/]+
tags:
- UserService
/api/v1/{parent}/tags:
get:
summary: ListMemoTags lists tags for a memo.
operationId: MemoService_ListMemoTags
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1ListMemoTagsResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: parent
description: |-
The parent, who owns the tags.
Format: memos/{id}. Use "memos/-" to list all tags.
in: path
required: true
type: string
pattern: memos/[^/]+
- name: filter
description: |-
Filter is used to filter memos.
Format: "creator == 'users/{uid}' && visibilities == ['PUBLIC', 'PROTECTED']"
in: query
required: false
type: string
tags:
- MemoService
/api/v1/{parent}/tags/{tag}:
delete:
summary: DeleteMemoTag deletes a tag for a memo.
......@@ -2532,14 +2491,6 @@ definitions:
items:
type: object
$ref: '#/definitions/v1Memo'
v1ListMemoPropertiesResponse:
type: object
properties:
entities:
type: array
items:
type: object
$ref: '#/definitions/v1MemoPropertyEntity'
v1ListMemoReactionsResponse:
type: object
properties:
......@@ -2564,18 +2515,6 @@ definitions:
items:
type: object
$ref: '#/definitions/v1Resource'
v1ListMemoTagsResponse:
type: object
properties:
tagAmounts:
type: object
additionalProperties:
type: integer
format: int32
description: |-
tag_amounts is the amount of tags.
key is the tag name. e.g. "tag1".
value is the amount of the tag.
v1ListMemosResponse:
type: object
properties:
......@@ -2734,21 +2673,6 @@ definitions:
type: boolean
hasIncompleteTasks:
type: boolean
v1MemoPropertyEntity:
type: object
properties:
name:
type: string
title: |-
The name of the memo property.
Format: memos/{id}/properties/{property_id}
property:
$ref: '#/definitions/v1MemoProperty'
readOnly: true
displayTime:
type: string
format: date-time
readOnly: true
v1MemoRelation:
type: object
properties:
......@@ -2771,6 +2695,16 @@ definitions:
- REFERENCE
- COMMENT
default: TYPE_UNSPECIFIED
v1MemoView:
type: string
enum:
- MEMO_VIEW_UNSPECIFIED
- MEMO_VIEW_FULL
- MEMO_VIEW_METADATA_ONLY
default: MEMO_VIEW_UNSPECIFIED
description: |2-
- MEMO_VIEW_FULL: The full view of the memo. Includes all fields.
- MEMO_VIEW_METADATA_ONLY: The metadata only view of the memo. Excludes the content/snippet fields.
v1Node:
type: object
properties:
......
......@@ -17,7 +17,6 @@ var authenticationAllowlistMethods = map[string]bool{
"/memos.api.v1.MemoService/GetMemo": true,
"/memos.api.v1.MemoService/GetMemoByUid": true,
"/memos.api.v1.MemoService/ListMemos": true,
"/memos.api.v1.MemoService/ListMemoTags": true,
"/memos.api.v1.MarkdownService/GetLinkMetadata": true,
"/memos.api.v1.ResourceService/GetResourceBinary": true,
"/memos.api.v1.ResourceService/GetResourceByUid": true,
......
This diff is collapsed.
......@@ -20,10 +20,14 @@ import useAsyncEffect from "@/hooks/useAsyncEffect";
import useCurrentUser from "@/hooks/useCurrentUser";
import i18n from "@/i18n";
import { useMemoFilterStore, useMemoList, useMemoStore } from "@/store/v1";
import { MemoView } from "@/types/proto/api/v1/memo_service";
import { useTranslate } from "@/utils/i18n";
import ActivityCalendar from "./ActivityCalendar";
import { Popover, PopoverContent, PopoverTrigger } from "./ui/Popover";
// Set the maximum number of memos to fetch.
const DEFAULT_MEMO_PAGE_SIZE = 1000000;
interface UserMemoStats {
link: number;
taskList: number;
......@@ -47,12 +51,13 @@ const UserStatisticsView = () => {
useAsyncEffect(async () => {
if (memoList.size() === 0) return;
const { entities } = await memoServiceClient.listMemoProperties({
name: `memos/-`,
const { memos } = await memoServiceClient.listMemos({
pageSize: DEFAULT_MEMO_PAGE_SIZE,
view: MemoView.MEMO_VIEW_METADATA_ONLY,
});
const memoStats: UserMemoStats = { link: 0, taskList: 0, code: 0, incompleteTasks: 0 };
entities.forEach((entity) => {
const { property } = entity;
memos.forEach((memo) => {
const { property } = memo;
if (property?.hasLink) {
memoStats.link += 1;
}
......@@ -67,11 +72,11 @@ const UserStatisticsView = () => {
}
});
setMemoStats(memoStats);
setMemoAmount(entities.length);
setActivityStats(countBy(entities.map((entity) => dayjs(entity.displayTime).format("YYYY-MM-DD"))));
setMemoAmount(memos.length);
setActivityStats(countBy(memos.map((memo) => dayjs(memo.displayTime).format("YYYY-MM-DD"))));
}, [memoStore.stateId]);
const rebuildMemoTags = async () => {
const rebuildMemoProperty = async () => {
await memoServiceClient.rebuildMemoProperty({
name: "memos/-",
});
......@@ -112,7 +117,7 @@ const UserStatisticsView = () => {
<MoreVerticalIcon className="w-4 h-auto shrink-0 opacity-60" />
</PopoverTrigger>
<PopoverContent align="end" alignOffset={-12}>
<button className="w-auto flex flex-row justify-between items-center gap-2 hover:opacity-80" onClick={rebuildMemoTags}>
<button className="w-auto flex flex-row justify-between items-center gap-2 hover:opacity-80" onClick={rebuildMemoProperty}>
<RefreshCcwIcon className="text-gray-400 w-4 h-auto cursor-pointer opacity-60" />
<span className="text-sm shrink-0 text-gray-500 dark:text-gray-400">Rebuild properties</span>
</button>
......
......@@ -3,8 +3,12 @@ import { create } from "zustand";
import { combine } from "zustand/middleware";
import { memoServiceClient } from "@/grpcweb";
import { Routes } from "@/router";
import { MemoView } from "@/types/proto/api/v1/memo_service";
import { User } from "@/types/proto/api/v1/user_service";
// Set the maximum number of memos to fetch.
const DEFAULT_MEMO_PAGE_SIZE = 1000000;
interface State {
tagAmounts: Record<string, number>;
}
......@@ -37,7 +41,21 @@ export const useTagStore = create(
} else {
filters.push(`visibilities == ["PUBLIC"]`);
}
const { tagAmounts } = await memoServiceClient.listMemoTags({ parent: "memos/-", filter: filters.join(" && ") });
const { memos } = await memoServiceClient.listMemos({
pageSize: DEFAULT_MEMO_PAGE_SIZE,
filter: filters.join(" && "),
view: MemoView.MEMO_VIEW_METADATA_ONLY,
});
const tagAmounts: Record<string, number> = {};
memos.forEach((memo) => {
memo.property?.tags.forEach((tag) => {
if (tagAmounts[tag]) {
tagAmounts[tag] += 1;
} else {
tagAmounts[tag] = 1;
}
});
});
set({ tagAmounts });
},
})),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment