Merge branch 'develop' into enhance-migration

This commit is contained in:
syuilo 2023-04-22 20:22:44 +09:00 committed by GitHub
commit 70d34aa05c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 63 deletions

View file

@ -23,8 +23,8 @@ export class FederatedInstanceService {
private idService: IdService, private idService: IdService,
) { ) {
this.federatedInstanceCache = new RedisKVCache<Instance | null>(this.redisClient, 'federatedInstance', { this.federatedInstanceCache = new RedisKVCache<Instance | null>(this.redisClient, 'federatedInstance', {
lifetime: 1000 * 60 * 60 * 24, // 24h lifetime: 1000 * 60 * 30, // 30m
memoryCacheLifetime: 1000 * 60 * 30, // 30m memoryCacheLifetime: 1000 * 60 * 3, // 3m
fetcher: (key) => this.instancesRepository.findOneBy({ host: key }), fetcher: (key) => this.instancesRepository.findOneBy({ host: key }),
toRedisConverter: (value) => JSON.stringify(value), toRedisConverter: (value) => JSON.stringify(value),
fromRedisConverter: (value) => { fromRedisConverter: (value) => {
@ -65,15 +65,18 @@ export class FederatedInstanceService {
} }
@bindThis @bindThis
public async updateCachePartial(host: string, data: Partial<Instance>): Promise<void> { public async update(id: Instance['id'], data: Partial<Instance>): Promise<void> {
host = this.utilityService.toPuny(host); const result = await this.instancesRepository.createQueryBuilder().update()
.set(data)
.where('id = :id', { id })
.returning('*')
.execute()
.then((response) => {
return response.raw[0];
});
const updated = result.raw[0];
const cached = await this.federatedInstanceCache.get(host); this.federatedInstanceCache.set(updated.host, updated);
if (cached == null) return;
this.federatedInstanceCache.set(host, {
...cached,
...data,
});
} }
} }

View file

@ -10,6 +10,7 @@ import { DI } from '@/di-symbols.js';
import { LoggerService } from '@/core/LoggerService.js'; import { LoggerService } from '@/core/LoggerService.js';
import { HttpRequestService } from '@/core/HttpRequestService.js'; import { HttpRequestService } from '@/core/HttpRequestService.js';
import { bindThis } from '@/decorators.js'; import { bindThis } from '@/decorators.js';
import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
import type { DOMWindow } from 'jsdom'; import type { DOMWindow } from 'jsdom';
type NodeInfo = { type NodeInfo = {
@ -42,6 +43,7 @@ export class FetchInstanceMetadataService {
private appLockService: AppLockService, private appLockService: AppLockService,
private httpRequestService: HttpRequestService, private httpRequestService: HttpRequestService,
private loggerService: LoggerService, private loggerService: LoggerService,
private federatedInstanceService: FederatedInstanceService,
) { ) {
this.logger = this.loggerService.getLogger('metadata', 'cyan'); this.logger = this.loggerService.getLogger('metadata', 'cyan');
} }
@ -96,7 +98,7 @@ export class FetchInstanceMetadataService {
if (favicon) updates.faviconUrl = favicon; if (favicon) updates.faviconUrl = favicon;
if (themeColor) updates.themeColor = themeColor; if (themeColor) updates.themeColor = themeColor;
await this.instancesRepository.update(instance.id, updates); await this.federatedInstanceService.update(instance.id, updates);
this.logger.succ(`Successfuly updated metadata of ${instance.host}`); this.logger.succ(`Successfuly updated metadata of ${instance.host}`);
} catch (e) { } catch (e) {

View file

@ -79,10 +79,7 @@ export class DeliverProcessorService {
// Update stats // Update stats
this.federatedInstanceService.fetch(host).then(i => { this.federatedInstanceService.fetch(host).then(i => {
if (i.isNotResponding) { if (i.isNotResponding) {
this.instancesRepository.update(i.id, { this.federatedInstanceService.update(i.id, {
isNotResponding: false,
});
this.federatedInstanceService.updateCachePartial(host, {
isNotResponding: false, isNotResponding: false,
}); });
} }
@ -101,10 +98,7 @@ export class DeliverProcessorService {
// Update stats // Update stats
this.federatedInstanceService.fetch(host).then(i => { this.federatedInstanceService.fetch(host).then(i => {
if (!i.isNotResponding) { if (!i.isNotResponding) {
this.instancesRepository.update(i.id, { this.federatedInstanceService.update(i.id, {
isNotResponding: true,
});
this.federatedInstanceService.updateCachePartial(host, {
isNotResponding: true, isNotResponding: true,
}); });
} }
@ -123,10 +117,7 @@ export class DeliverProcessorService {
// 相手が閉鎖していることを明示しているため、配送停止する // 相手が閉鎖していることを明示しているため、配送停止する
if (job.data.isSharedInbox && res.statusCode === 410) { if (job.data.isSharedInbox && res.statusCode === 410) {
this.federatedInstanceService.fetch(host).then(i => { this.federatedInstanceService.fetch(host).then(i => {
this.instancesRepository.update(i.id, { this.federatedInstanceService.update(i.id, {
isSuspended: true,
});
this.federatedInstanceService.updateCachePartial(host, {
isSuspended: true, isSuspended: true,
}); });
}); });

View file

@ -174,13 +174,10 @@ export class InboxProcessorService {
// Update stats // Update stats
this.federatedInstanceService.fetch(authUser.user.host).then(i => { this.federatedInstanceService.fetch(authUser.user.host).then(i => {
this.instancesRepository.update(i.id, { this.federatedInstanceService.update(i.id, {
latestRequestReceivedAt: new Date(), latestRequestReceivedAt: new Date(),
isNotResponding: false, isNotResponding: false,
}); });
this.federatedInstanceService.updateCachePartial(host, {
isNotResponding: false,
});
this.fetchInstanceMetadataService.fetchInstanceMetadata(i); this.fetchInstanceMetadataService.fetchInstanceMetadata(i);

View file

@ -3,6 +3,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import type { InstancesRepository } from '@/models/index.js'; import type { InstancesRepository } from '@/models/index.js';
import { UtilityService } from '@/core/UtilityService.js'; import { UtilityService } from '@/core/UtilityService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
export const meta = { export const meta = {
tags: ['admin'], tags: ['admin'],
@ -28,6 +29,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private instancesRepository: InstancesRepository, private instancesRepository: InstancesRepository,
private utilityService: UtilityService, private utilityService: UtilityService,
private federatedInstanceService: FederatedInstanceService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(meta, paramDef, async (ps, me) => {
const instance = await this.instancesRepository.findOneBy({ host: this.utilityService.toPuny(ps.host) }); const instance = await this.instancesRepository.findOneBy({ host: this.utilityService.toPuny(ps.host) });
@ -36,7 +38,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
throw new Error('instance not found'); throw new Error('instance not found');
} }
this.instancesRepository.update({ host: this.utilityService.toPuny(ps.host) }, { this.federatedInstanceService.update(instance.id, {
isSuspended: ps.isSuspended, isSuspended: ps.isSuspended,
}); });
}); });

View file

@ -1,47 +1,32 @@
<template> <template>
<span class="ceaaebcd" :class="{ isPlus, isMinus, isZero }"> <span class="ceaaebcd" :class="{ [$style.isPlus]: isPlus, [$style.isMinus]: isMinus, [$style.isZero]: isZero }">
<slot name="before"></slot>{{ isPlus ? '+' : '' }}{{ number(value) }}<slot name="after"></slot> <slot name="before"></slot>{{ isPlus ? '+' : '' }}{{ number(value) }}<slot name="after"></slot>
</span> </span>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { computed, defineComponent } from 'vue'; import { computed } from 'vue';
import number from '@/filters/number'; import number from '@/filters/number';
export default defineComponent({ const props = defineProps<{
props: { value: number;
value: { }>();
type: Number,
required: true,
},
},
setup(props) { const isPlus = computed(() => props.value > 0);
const isPlus = computed(() => props.value > 0); const isMinus = computed(() => props.value < 0);
const isMinus = computed(() => props.value < 0); const isZero = computed(() => props.value === 0);
const isZero = computed(() => props.value === 0);
return {
isPlus,
isMinus,
isZero,
number,
};
},
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" module>
.ceaaebcd { .isPlus {
&.isPlus { color: var(--success);
color: var(--success); }
}
&.isMinus { .isMinus {
color: var(--error); color: var(--error);
} }
&.isZero { .isZero {
opacity: 0.5; opacity: 0.5;
}
} }
</style> </style>

View file

@ -243,7 +243,7 @@ function onDrop(ev) {
<style lang="scss" module> <style lang="scss" module>
.root { .root {
--root-margin: 10px; --root-margin: 10px;
--deckColumnHeaderHeight: 40px; --deckColumnHeaderHeight: 38px;
height: 100%; height: 100%;
overflow: clip; overflow: clip;