fix performance

This commit is contained in:
samunohito 2024-02-04 09:24:10 +09:00
parent b37a27e154
commit 4cb7e984aa
7 changed files with 73 additions and 56 deletions

View File

@ -97,7 +97,7 @@ class MyCustomLogger implements Logger {
@bindThis @bindThis
public logQuery(query: string, parameters?: any[]) { public logQuery(query: string, parameters?: any[]) {
sqlLogger.info(this.highlight(query).substring(0, 100)); sqlLogger.info(this.highlight(query));
} }
@bindThis @bindThis

View File

@ -53,7 +53,6 @@
import { import {
computed, computed,
defineAsyncComponent, defineAsyncComponent,
getCurrentInstance,
nextTick, nextTick,
onMounted, onMounted,
onUnmounted, onUnmounted,
@ -101,7 +100,7 @@ const needsContentCentering = computed(() => {
} }
}); });
watch(() => [cell, cell.value.value], () => { watch(() => [cell.value.value], () => {
// //
nextTick(emitContentSizeChanged); nextTick(emitContentSizeChanged);
}, { immediate: true }); }, { immediate: true });
@ -112,10 +111,6 @@ watch(() => cell.value.selected, () => {
} }
}); });
watch(() => cell.value.value, (newValue) => {
emitValueChange(newValue);
});
function onCellDoubleClick(ev: MouseEvent) { function onCellDoubleClick(ev: MouseEvent) {
switch (ev.type) { switch (ev.type) {
case 'dblclick': { case 'dblclick': {

View File

@ -20,7 +20,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { getCurrentInstance, toRefs, watch } from 'vue'; import { toRefs } from 'vue';
import { GridEventEmitter, GridSetting, Size } from '@/components/grid/grid.js'; import { GridEventEmitter, GridSetting, Size } from '@/components/grid/grid.js';
import MkDataCell from '@/components/grid/MkDataCell.vue'; import MkDataCell from '@/components/grid/MkDataCell.vue';
import MkNumberCell from '@/components/grid/MkNumberCell.vue'; import MkNumberCell from '@/components/grid/MkNumberCell.vue';

View File

@ -36,7 +36,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, onMounted, ref, toRefs, watch } from 'vue'; import { computed, nextTick, onMounted, ref, toRefs, watch } from 'vue';
import { DataSource, GridEventEmitter, GridSetting, GridState, Size } from '@/components/grid/grid.js'; import { DataSource, GridEventEmitter, GridSetting, GridState, Size } from '@/components/grid/grid.js';
import MkDataRow from '@/components/grid/MkDataRow.vue'; import MkDataRow from '@/components/grid/MkDataRow.vue';
import MkHeaderRow from '@/components/grid/MkHeaderRow.vue'; import MkHeaderRow from '@/components/grid/MkHeaderRow.vue';
@ -649,9 +649,15 @@ function onChangeCellValue(sender: GridCell, newValue: CellValue) {
} }
function onChangeCellContentSize(sender: GridCell, contentSize: Size) { function onChangeCellContentSize(sender: GridCell, contentSize: Size) {
cells.value[sender.address.row].cells[sender.address.col].contentSize = contentSize; const _cells = cells.value;
if (sender.column.setting.width === 'auto') { if (_cells.length > sender.address.row && _cells[sender.address.row].cells.length > sender.address.col) {
calcLargestCellWidth(sender.column); const currentSize = _cells[sender.address.row].cells[sender.address.col].contentSize;
if (currentSize.width !== contentSize.width || currentSize.height !== contentSize.height) {
_cells[sender.address.row].cells[sender.address.col].contentSize = contentSize;
if (sender.column.setting.width === 'auto') {
calcLargestCellWidth(sender.column);
}
}
} }
} }
@ -686,9 +692,12 @@ function onHeaderCellChangeWidth(sender: GridColumn, width: string) {
function onHeaderCellChangeContentSize(sender: GridColumn, newSize: Size) { function onHeaderCellChangeContentSize(sender: GridColumn, newSize: Size) {
switch (state.value) { switch (state.value) {
case 'normal': { case 'normal': {
columns.value[sender.index].contentSize = newSize; const currentSize = columns.value[sender.index].contentSize;
if (sender.setting.width === 'auto') { if (currentSize.width !== newSize.width || currentSize.height !== newSize.height) {
calcLargestCellWidth(sender); columns.value[sender.index].contentSize = newSize;
if (sender.setting.width === 'auto') {
calcLargestCellWidth(sender);
}
} }
break; break;
} }
@ -924,7 +933,7 @@ function refreshColumnsSetting() {
function refreshData() { function refreshData() {
if (_DEV_) { if (_DEV_) {
console.log('[grid][refresh-data]'); console.log('[grid][refresh-data][begin]');
} }
const _data: DataSource[] = data.value; const _data: DataSource[] = data.value;
@ -954,6 +963,10 @@ function refreshData() {
rows.value = _rows; rows.value = _rows;
columns.value = _cols; columns.value = _cols;
cells.value = _cells; cells.value = _cells;
if (_DEV_) {
console.log('[grid][refresh-data][end]');
}
} }
/** /**
@ -967,51 +980,34 @@ function refreshData() {
* そこで新しい値とセルが持つ値を突き合わせ変更があった場合のみ値を更新しセルそのものは使いまわしつつ値を最新化する * そこで新しい値とセルが持つ値を突き合わせ変更があった場合のみ値を更新しセルそのものは使いまわしつつ値を最新化する
*/ */
function patchData(newItems: DataSource[]) { function patchData(newItems: DataSource[]) {
const gridRows = [...cells.value]; if (_DEV_) {
if (gridRows.length > newItems.length) { console.log(`[grid][patch-data][begin] new:${newItems.length} old:${cells.value.length}`);
// }
const _cells = [...cells.value];
const _rows = [...rows.value];
const _cols = columns.value;
if (_cells.length != newItems.length) {
// //
unSelectionRangeAll(); unSelectionRangeAll();
const diff = gridRows const oldOrigins = _cells.map(it => it.origin);
.map((it, idx) => ({ origin: it.origin, idx }))
.filter(it => !newItems.includes(it.origin))
.map(it => it.idx);
const newRows = rows.value.filter((_, idx) => !diff.includes(idx));
const newCells = gridRows.filter((_, idx) => !diff.includes(idx));
//
for (let rowIdx = 0; rowIdx < newRows.length; rowIdx++) {
newRows[rowIdx].index = rowIdx;
for (const cell of newCells[rowIdx].cells) {
cell.address.row = rowIdx;
}
}
rows.value = newRows;
cells.value = newCells;
} else if (gridRows.length < newItems.length) {
//
//
unSelectionRangeAll();
const oldOrigins = gridRows.map(it => it.origin);
const newRows = Array.of<GridRow>(); const newRows = Array.of<GridRow>();
const newCells = Array.of<RowHolder>(); const newCells = Array.of<RowHolder>();
for (const it of newItems) { for (const it of newItems) {
const idx = oldOrigins.indexOf(it); const idx = oldOrigins.indexOf(it);
if (idx >= 0) { if (idx >= 0) {
// //
newRows.push(rows.value[idx]); newRows.push(_rows[idx]);
newCells.push(gridRows[idx]); newCells.push(_cells[idx]);
} else { } else {
// //
const newRow = createRow(newRows.length); const newRow = createRow(newRows.length);
newRows.push(newRow); newRows.push(newRow);
newCells.push({ newCells.push({
cells: columns.value.map(col => { cells: _cols.map(col => {
const cell = createCell(col, newRow, it[col.setting.bindTo]); const cell = createCell(col, newRow, it[col.setting.bindTo]);
cell.violation = cellValidation(cell, cell.value); cell.violation = cellValidation(cell, cell.value);
return cell; return cell;
@ -1021,7 +1017,7 @@ function patchData(newItems: DataSource[]) {
} }
} }
// //
for (let rowIdx = 0; rowIdx < newCells.length; rowIdx++) { for (let rowIdx = 0; rowIdx < newCells.length; rowIdx++) {
newRows[rowIdx].index = rowIdx; newRows[rowIdx].index = rowIdx;
for (const cell of newCells[rowIdx].cells) { for (const cell of newCells[rowIdx].cells) {
@ -1033,9 +1029,8 @@ function patchData(newItems: DataSource[]) {
cells.value = newCells; cells.value = newCells;
} else { } else {
// //
const _cols = columns.value; for (let rowIdx = 0; rowIdx < _cells.length; rowIdx++) {
for (let rowIdx = 0; rowIdx < gridRows.length; rowIdx++) { const oldCells = _cells[rowIdx].cells;
const oldCells = gridRows[rowIdx].cells;
const newItem = newItems[rowIdx]; const newItem = newItems[rowIdx];
for (let colIdx = 0; colIdx < oldCells.length; colIdx++) { for (let colIdx = 0; colIdx < oldCells.length; colIdx++) {
const _col = _cols[colIdx]; const _col = _cols[colIdx];
@ -1049,6 +1044,16 @@ function patchData(newItems: DataSource[]) {
} }
} }
} }
//
emitGridEvent({
type: 'cell-validation',
all: cells.value.flatMap(it => it.cells).map(it => it.violation).filter(it => !it.valid),
});
if (_DEV_) {
console.log('[grid][patch-data][end]');
}
} }
// endregion // endregion

View File

@ -43,7 +43,7 @@ export type GridCellValueChangeEvent = {
export type GridCellValidationEvent = { export type GridCellValidationEvent = {
type: 'cell-validation'; type: 'cell-validation';
violation: ValidateViolation; violation?: ValidateViolation;
all: ValidateViolation[]; all: ValidateViolation[];
}; };

View File

@ -12,13 +12,13 @@
<div <div
style="overflow-y: scroll; padding-top: 8px; padding-bottom: 8px;" style="overflow-y: scroll; padding-top: 8px; padding-bottom: 8px;"
> >
<MkGrid :data="convertedGridItems" :columnSettings="columnSettings"/> <MkGrid :data="gridItems" :columnSettings="columnSettings"/>
</div> </div>
<div class="_gaps"> <div class="_gaps">
<div :class="$style.pages"> <div :class="$style.pages">
<button>&lt;</button> <button @click="onLatestButtonClicked">&lt;</button>
<button>&gt;</button> <button @click="onOldestButtonClicked">&gt;</button>
</div> </div>
<div :class="$style.buttons"> <div :class="$style.buttons">
@ -66,7 +66,8 @@ const { customEmojis } = toRefs(props);
const query = ref(''); const query = ref('');
const gridItems = ref<GridItem[]>([]); const gridItems = ref<GridItem[]>([]);
const convertedGridItems = computed(() => gridItems.value.map(it => it as Record<string, any>)); const latest = computed(() => customEmojis.value.length > 0 ? customEmojis.value[0]?.id : undefined);
const oldest = computed(() => customEmojis.value.length > 0 ? customEmojis.value[customEmojis.value.length - 1]?.id : undefined);
watch(customEmojis, refreshGridItems); watch(customEmojis, refreshGridItems);
@ -74,6 +75,14 @@ function onSearchButtonClicked() {
emit('operation:search', query.value, undefined, undefined); emit('operation:search', query.value, undefined, undefined);
} }
async function onLatestButtonClicked() {
emit('operation:search', query.value, latest.value, undefined);
}
async function onOldestButtonClicked() {
emit('operation:search', query.value, undefined, oldest.value);
}
function refreshGridItems() { function refreshGridItems() {
gridItems.value = customEmojis.value.map(it => fromEmojiDetailed(it)); gridItems.value = customEmojis.value.map(it => fromEmojiDetailed(it));
} }

View File

@ -32,6 +32,7 @@ import * as Misskey from 'misskey-js';
import { misskeyApi } from '@/scripts/misskey-api.js'; import { misskeyApi } from '@/scripts/misskey-api.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js'; import { definePageMetadata } from '@/scripts/page-metadata.js';
import * as os from '@/os.js';
import MkTab from '@/components/MkTab.vue'; import MkTab from '@/components/MkTab.vue';
import XListComponent from '@/pages/admin/custom-emojis-grid.list.vue'; import XListComponent from '@/pages/admin/custom-emojis-grid.list.vue';
import XRegisterComponent from '@/pages/admin/custom-emojis-grid.register.vue'; import XRegisterComponent from '@/pages/admin/custom-emojis-grid.register.vue';
@ -44,12 +45,19 @@ const modeTab = ref<PageMode>('list');
const query = ref<string>(); const query = ref<string>();
async function refreshCustomEmojis(query?: string, sinceId?: string, untilId?: string) { async function refreshCustomEmojis(query?: string, sinceId?: string, untilId?: string) {
customEmojis.value = await misskeyApi('admin/emoji/list', { const emojis = await misskeyApi('admin/emoji/list', {
limit: 100, limit: 100,
query, query,
sinceId, sinceId,
untilId, untilId,
}); });
if (sinceId) {
// IDsinceId
emojis.reverse();
}
customEmojis.value = emojis;
} }
async function onOperationSearch(q: string, sinceId?: string, untilId?: string) { async function onOperationSearch(q: string, sinceId?: string, untilId?: string) {