From c81b81db9de9aa479576219604558d17b728281d Mon Sep 17 00:00:00 2001 From: n0099 Date: Mon, 11 Mar 2024 01:01:12 +0800 Subject: [PATCH] - route `/status` that was originally introduced in 2019: 3460ecc10fd57392db49cda2831ce1958a0eae28 and broken after migrated crawler to c# in June 2022 - route `/stats` that broken as of renaming field `postTime` to `postedAt` in 429de6ad500ea3ed82bd918eda81bd435c24d4ba @ `be/routes/api.php` - unused exports `throwIfApiError()`, `useApiStatus()` & `useApiStatsForumsPostCount()` @ index.ts - unused exports `ApiStatus` & `ApiStatsForumPostCount`, and interface `TimeCountPair` @ index.d.ts @ api - route `/status` & `/stats` @ router/index.ts & `` - unused exports `commonToolboxFeatures`, `extendCommonToolbox()` & `emptyChartSeriesData()` @ shared/echarts.ts $ rm views/Stat{,u}s.vue shared/groupByTimeGranularityUtcPlus8.d.ts @ fe --- be/routes/api.php | 69 ------ fe/src/api/index.d.ts | 29 +-- fe/src/api/index.ts | 10 +- fe/src/components/GlobalNavBar.vue | 2 - fe/src/router/index.ts | 2 - fe/src/shared/echarts.ts | 26 --- .../groupByTimeGranularityUtcPlus8.d.ts | 7 - fe/src/views/Stats.vue | 172 -------------- fe/src/views/Status.vue | 218 ------------------ 9 files changed, 2 insertions(+), 533 deletions(-) delete mode 100644 fe/src/shared/groupByTimeGranularityUtcPlus8.d.ts delete mode 100644 fe/src/views/Stats.vue delete mode 100644 fe/src/views/Status.vue diff --git a/be/routes/api.php b/be/routes/api.php index 16d62e30..3714b3c5 100644 --- a/be/routes/api.php +++ b/be/routes/api.php @@ -1,14 +1,9 @@ group(static function () { Route::get('/posts', [PostsQuery::class, 'query']); Route::get('/users', [UsersQuery::class, 'query']); - Route::get('/status', static function (Request $request): string { - $groupByTimeGranularity = [ - 'minute' => 'FROM_UNIXTIME(startTime, "%Y-%m-%d %H:%i") AS startTime', - 'hour' => 'FROM_UNIXTIME(startTime, "%Y-%m-%d %H:00") AS startTime', - 'day' => 'FROM_UNIXTIME(startTime, "%Y-%m-%d") AS startTime', - ]; - - /** @var array{timeGranularity: string, startTime: string, endTime: string} $queryParams */ - $queryParams = $request->validate([ - 'timeGranularity' => ['required', 'string', Rule::in(array_keys($groupByTimeGranularity))], - 'startTime' => 'required|integer|numeric', - 'endTime' => 'required|integer|numeric' - ]); - - return DB::query() - ->selectRaw(' - CAST(UNIX_TIMESTAMP(startTime) AS UNSIGNED) AS startTime, - SUM(queueTiming) AS queueTiming, - SUM(webRequestTiming) AS webRequestTiming, - SUM(savePostsTiming) AS savePostsTiming, - CAST(SUM(webRequestTimes) AS UNSIGNED) AS webRequestTimes, - CAST(SUM(parsedPostTimes) AS UNSIGNED) AS parsedPostTimes, - CAST(SUM(parsedUserTimes) AS UNSIGNED) AS parsedUserTimes - ') - ->fromSub(static fn (Builder $query) => - $query->from('tbm_crawledPosts') - ->selectRaw($groupByTimeGranularity[$queryParams['timeGranularity']]) - ->selectRaw(' - queueTiming, - webRequestTiming, - savePostsTiming, - webRequestTimes, - parsedPostTimes, - parsedUserTimes - ') - ->whereBetween('startTime', [$queryParams['startTime'], $queryParams['endTime']]) - ->orderBy('id', 'DESC'), 'T') - ->groupBy('startTime') - ->get()->toJson(); - }); - Route::get('/stats/forums/postCount', static function (Request $request): array { - $groupByTimeGranularity = Helper::rawSqlGroupByTimeGranularity('postTime'); - $queryParams = $request->validate([ - 'fid' => 'required|integer', - 'timeGranularity' => ['required', 'string', Rule::in(array_keys($groupByTimeGranularity))], - 'startTime' => 'required|integer|numeric', - 'endTime' => 'required|integer|numeric' - ]); - - $forumsPostCount = []; - foreach (PostFactory::getPostModelsByFid($queryParams['fid']) as $postType => $forumPostModel) { - /** @var \Illuminate\Database\Eloquent\Model $forumPostModel */ - $forumsPostCount[$postType] = $forumPostModel - ->selectRaw($groupByTimeGranularity[$queryParams['timeGranularity']]) - ->selectRaw('COUNT(*) AS count') - ->whereBetween('postTime', [Helper::timestampToLocalDateTime($queryParams['startTime']), Helper::timestampToLocalDateTime($queryParams['endTime'])]) - ->groupBy('time') - ->orderBy('time') - ->get()->toArray(); - } - Helper::abortAPIIf(40403, collect($forumsPostCount)->every(fn ($i) => $i === [])); - - return $forumsPostCount; - }); }); diff --git a/fe/src/api/index.d.ts b/fe/src/api/index.d.ts index 62b31c10..04bc3c0c 100644 --- a/fe/src/api/index.d.ts +++ b/fe/src/api/index.d.ts @@ -1,8 +1,7 @@ import type { Reply, SubReply, Thread } from './post'; import type { User, UserGenderQueryParam } from './user'; import type { SelectUserParams } from '@/components/widgets/selectUser'; -import type { BoolInt, Fid, Float, PostType, UInt, UnixTimestamp } from '@/shared'; -import type { Mix } from '@/shared/groupBytimeGranularityUtcPlus8'; +import type { BoolInt, Fid, PostType, UInt } from '@/shared'; export interface ApiError { errorCode: number, errorInfo: Record | string } export interface Api { @@ -17,32 +16,6 @@ export type ApiForums = Api>; -export type ApiStatus = Api, { - timeGranularity: 'day' | 'hour' | 'minute', - startTime: UnixTimestamp, - endTime: UnixTimestamp - }>; - -interface TimeCountPair { time: Mix, count: UInt } -export type ApiStatsForumPostCount = Api<{ - thread: TimeCountPair[], - reply: TimeCountPair[], - subReply: TimeCountPair[] -}, { - fid: Fid, - timeGranularity: 'day' | 'hour' | 'minute' | 'month' | 'week' | 'year', - startTime: UnixTimestamp, - endTime: UnixTimestamp - }>; - export type Cursor = string; interface CursorPagination { pages: { diff --git a/fe/src/api/index.ts b/fe/src/api/index.ts index 0492315f..4c78facc 100644 --- a/fe/src/api/index.ts +++ b/fe/src/api/index.ts @@ -1,4 +1,4 @@ -import type { Api, ApiError, ApiForums, ApiPosts, ApiStatsForumPostCount, ApiStatus, ApiUsers, Cursor, CursorPagination } from '@/api/index.d'; +import type { Api, ApiError, ApiForums, ApiPosts, ApiUsers, Cursor, CursorPagination } from '@/api/index.d'; import type { Ref } from 'vue'; import type { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseQueryOptions } from '@tanstack/vue-query'; import { useInfiniteQuery, useQuery } from '@tanstack/vue-query'; @@ -23,12 +23,6 @@ export class FetchResponseError extends Error { export const isApiError = (response: ApiError | unknown): response is ApiError => _.isObject(response) && 'errorCode' in response && _.isNumber(response.errorCode) && 'errorInfo' in response && (_.isObject(response.errorInfo) || _.isString(response.errorInfo)); -export const throwIfApiError = (response: ApiError | TResponse): TResponse => { - if (isApiError(response)) - throw new Error(JSON.stringify(response)); - - return response; -}; export const queryFunction = async (endpoint: string, queryParam?: TQueryParam, signal?: AbortSignal): Promise => { nprogress.start(); @@ -119,7 +113,5 @@ const useApiWithCursor = < }); export const useApiForums = () => useApi('forums', queryFunction)(); -export const useApiStatus = useApi('status', queryFunctionWithReCAPTCHA); -export const useApiStatsForumsPostCount = useApi('stats/forums/postCount', queryFunctionWithReCAPTCHA); export const useApiUsers = useApi('users', queryFunctionWithReCAPTCHA); export const useApiPosts = useApiWithCursor('posts', queryFunctionWithReCAPTCHA); diff --git a/fe/src/components/GlobalNavBar.vue b/fe/src/components/GlobalNavBar.vue index bf6020c0..2bc6eb2c 100644 --- a/fe/src/components/GlobalNavBar.vue +++ b/fe/src/components/GlobalNavBar.vue @@ -52,8 +52,6 @@ const navs = reactive>([ { route: 'user', title: '用户', icon: 'users' } ] }, - { route: 'stats', title: '统计', icon: 'chart-pie' }, - { route: 'status', title: '状态', icon: 'satellite-dish' }, { title: '专题', icon: 'paper-plane', diff --git a/fe/src/router/index.ts b/fe/src/router/index.ts index 3f5cfc01..d5037c0b 100644 --- a/fe/src/router/index.ts +++ b/fe/src/router/index.ts @@ -123,8 +123,6 @@ export default createRouter({ withCursorRoute(userRoute, 'displayName/:displayName', 'user/displayName') ] }), - withViewRoute(import('@/views/Status.vue'), 'status'), - withViewRoute(import('@/views/Stats.vue'), 'stats'), withViewRoute(import('@/views/BilibiliVote.vue'), 'bilibiliVote') ], linkActiveClass: 'active', diff --git a/fe/src/shared/echarts.ts b/fe/src/shared/echarts.ts index bf2033dc..028fd9f5 100644 --- a/fe/src/shared/echarts.ts +++ b/fe/src/shared/echarts.ts @@ -1,8 +1,5 @@ import { DateTime } from 'luxon'; import * as _ from 'lodash-es'; - -import type { BarSeriesOption, LineSeriesOption } from 'echarts/charts'; -import type { ToolboxComponentOption } from 'echarts/components'; import * as echarts from 'echarts/core'; // eslint-disable-next-line import/extensions import type { ColorPaletteOptionMixin } from 'echarts/types/src/util/types.d.ts'; @@ -28,29 +25,6 @@ export const echarts4ColorTheme: ColorPaletteOptionMixin = { ] }; -export const commonToolboxFeatures: echarts.ComposeOption = { - toolbox: { - feature: { - dataZoom: { show: true, yAxisIndex: 'none' }, - saveAsImage: { show: true } - } - } -}; -export const extendCommonToolbox = (extend: echarts.ComposeOption) -: echarts.ComposeOption => - _.merge(commonToolboxFeatures, extend); - -export const emptyChartSeriesData = (chart: echarts.ECharts) => { - chart.setOption({ - series: _.map(chart.getOption().series as BarSeriesOption | LineSeriesOption, series => { - if (_.isObject(series) && 'data' in series) - series.data = []; - - return series; - }) - }); -}; - export const timeGranularities = ['minute', 'hour', 'day', 'week', 'month', 'year'] as const; export type TimeGranularity = typeof timeGranularities[number]; export type TimeGranularityStringMap = { [P in TimeGranularity]?: string }; diff --git a/fe/src/shared/groupByTimeGranularityUtcPlus8.d.ts b/fe/src/shared/groupByTimeGranularityUtcPlus8.d.ts deleted file mode 100644 index bf0c4132..00000000 --- a/fe/src/shared/groupByTimeGranularityUtcPlus8.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -export type Minute = string; // "2020-10-10 00:11" -export type Hour = string; // "2020-10-10 00:00" -export type Day = string; // "2020-10-10" -export type Week = string; // "2020年第1周" -export type Month = string; // "2020-10" -export type Year = string; // "2020年" -export type Mix = Day | Hour | Minute | Month | Week | Year; diff --git a/fe/src/views/Stats.vue b/fe/src/views/Stats.vue deleted file mode 100644 index a43017b5..00000000 --- a/fe/src/views/Stats.vue +++ /dev/null @@ -1,172 +0,0 @@ - - - - - diff --git a/fe/src/views/Status.vue b/fe/src/views/Status.vue deleted file mode 100644 index 91d7b62d..00000000 --- a/fe/src/views/Status.vue +++ /dev/null @@ -1,218 +0,0 @@ - - - - -