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
public logQuery(query: string, parameters?: any[]) {
sqlLogger.info(this.highlight(query).substring(0, 100));
sqlLogger.info(this.highlight(query));
}
@bindThis

View file

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

View file

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

View file

@ -36,7 +36,7 @@
</template>
<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 MkDataRow from '@/components/grid/MkDataRow.vue';
import MkHeaderRow from '@/components/grid/MkHeaderRow.vue';
@ -649,9 +649,15 @@ function onChangeCellValue(sender: GridCell, newValue: CellValue) {
}
function onChangeCellContentSize(sender: GridCell, contentSize: Size) {
cells.value[sender.address.row].cells[sender.address.col].contentSize = contentSize;
if (sender.column.setting.width === 'auto') {
calcLargestCellWidth(sender.column);
const _cells = cells.value;
if (_cells.length > sender.address.row && _cells[sender.address.row].cells.length > sender.address.col) {
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) {
switch (state.value) {
case 'normal': {
columns.value[sender.index].contentSize = newSize;
if (sender.setting.width === 'auto') {
calcLargestCellWidth(sender);
const currentSize = columns.value[sender.index].contentSize;
if (currentSize.width !== newSize.width || currentSize.height !== newSize.height) {
columns.value[sender.index].contentSize = newSize;
if (sender.setting.width === 'auto') {
calcLargestCellWidth(sender);
}
}
break;
}
@ -924,7 +933,7 @@ function refreshColumnsSetting() {
function refreshData() {
if (_DEV_) {
console.log('[grid][refresh-data]');
console.log('[grid][refresh-data][begin]');
}
const _data: DataSource[] = data.value;
@ -954,6 +963,10 @@ function refreshData() {
rows.value = _rows;
columns.value = _cols;
cells.value = _cells;
if (_DEV_) {
console.log('[grid][refresh-data][end]');
}
}
/**
@ -967,51 +980,34 @@ function refreshData() {
* そこで新しい値とセルが持つ値を突き合わせ変更があった場合のみ値を更新しセルそのものは使いまわしつつ値を最新化する
*/
function patchData(newItems: DataSource[]) {
const gridRows = [...cells.value];
if (gridRows.length > newItems.length) {
//
if (_DEV_) {
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();
const diff = gridRows
.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 oldOrigins = _cells.map(it => it.origin);
const newRows = Array.of<GridRow>();
const newCells = Array.of<RowHolder>();
for (const it of newItems) {
const idx = oldOrigins.indexOf(it);
if (idx >= 0) {
//
newRows.push(rows.value[idx]);
newCells.push(gridRows[idx]);
newRows.push(_rows[idx]);
newCells.push(_cells[idx]);
} else {
//
const newRow = createRow(newRows.length);
newRows.push(newRow);
newCells.push({
cells: columns.value.map(col => {
cells: _cols.map(col => {
const cell = createCell(col, newRow, it[col.setting.bindTo]);
cell.violation = cellValidation(cell, cell.value);
return cell;
@ -1021,7 +1017,7 @@ function patchData(newItems: DataSource[]) {
}
}
//
//
for (let rowIdx = 0; rowIdx < newCells.length; rowIdx++) {
newRows[rowIdx].index = rowIdx;
for (const cell of newCells[rowIdx].cells) {
@ -1033,9 +1029,8 @@ function patchData(newItems: DataSource[]) {
cells.value = newCells;
} else {
//
const _cols = columns.value;
for (let rowIdx = 0; rowIdx < gridRows.length; rowIdx++) {
const oldCells = gridRows[rowIdx].cells;
for (let rowIdx = 0; rowIdx < _cells.length; rowIdx++) {
const oldCells = _cells[rowIdx].cells;
const newItem = newItems[rowIdx];
for (let colIdx = 0; colIdx < oldCells.length; 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

View file

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

View file

@ -12,13 +12,13 @@
<div
style="overflow-y: scroll; padding-top: 8px; padding-bottom: 8px;"
>
<MkGrid :data="convertedGridItems" :columnSettings="columnSettings"/>
<MkGrid :data="gridItems" :columnSettings="columnSettings"/>
</div>
<div class="_gaps">
<div :class="$style.pages">
<button>&lt;</button>
<button>&gt;</button>
<button @click="onLatestButtonClicked">&lt;</button>
<button @click="onOldestButtonClicked">&gt;</button>
</div>
<div :class="$style.buttons">
@ -66,7 +66,8 @@ const { customEmojis } = toRefs(props);
const query = ref('');
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);
@ -74,6 +75,14 @@ function onSearchButtonClicked() {
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() {
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 { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import * as os from '@/os.js';
import MkTab from '@/components/MkTab.vue';
import XListComponent from '@/pages/admin/custom-emojis-grid.list.vue';
import XRegisterComponent from '@/pages/admin/custom-emojis-grid.register.vue';
@ -44,12 +45,19 @@ const modeTab = ref<PageMode>('list');
const query = ref<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,
query,
sinceId,
untilId,
});
if (sinceId) {
// IDsinceId
emojis.reverse();
}
customEmojis.value = emojis;
}
async function onOperationSearch(q: string, sinceId?: string, untilId?: string) {