Skip to content

Commit 74a37d3

Browse files
authored
未ログオンページでのキャッシュの強化 (#4572)
* GET APIでstring Arrayをサポート * 未ログイントップのキャッシュ * users/get-frequently-replied-users * user * note * explore * featured * search
1 parent a80111e commit 74a37d3

38 files changed

+60
-32
lines changed

src/client/app/common/views/deck/deck.hashtag-tl.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default Vue.extend({
3030
return {
3131
connection: null,
3232
date: null as Date | null,
33-
makePromise: (cursor: string) => this.$root.api('notes/search_by_tag', {
33+
makePromise: (cursor: string) => this.$root.api('notes/search-by-tag', {
3434
limit: fetchLimit + 1,
3535
untilId: (!this.date && cursor) ? cursor : undefined,
3636
untilDate: this.date ? this.date.getTime() : undefined,

src/client/app/common/views/deck/deck.user-column.home.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default Vue.extend({
8989
makePromise: null,
9090
date: null as Date | null,
9191
faCalendarAlt,
92-
makeFrequentlyRepliedUsersPromise: () => this.$root.api('users/get_frequently_replied_users', {
92+
makeFrequentlyRepliedUsersPromise: () => this.$root.api('users/get-frequently-replied-users', {
9393
userId: this.user.id,
9494
limit: 5,
9595
}).then(res => res.map(x => x.user)),

src/client/app/common/views/pages/explore.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,14 @@ export default Vue.extend({
246246
sort: '+attachedLocalUsers',
247247
attachedToLocalUserOnly: true,
248248
limit: 30
249-
}).then(tags => {
249+
}, false, true).then(tags => {
250250
this.tagsLocal = tags;
251251
});
252252
this.$root.api('hashtags/list', {
253253
sort: '+attachedRemoteUsers',
254254
attachedToRemoteUserOnly: true,
255255
limit: 30
256-
}).then(tags => {
256+
}, false, true).then(tags => {
257257
this.tagsRemote = tags;
258258
});
259259
this.$root.api('stats', {}, false, true).then(stats => {

src/client/app/desktop/views/components/note-detail.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export default Vue.extend({
147147
this.$root.api('notes/children', {
148148
noteId: this.appearNote.id,
149149
limit: 30
150-
}).then(replies => {
150+
}, false, !this.$store.getters.isSignedIn).then(replies => {
151151
this.replies = replies;
152152
});
153153
}

src/client/app/desktop/views/home/featured.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default Vue.extend({
7979
fileType: this.mediaOnly ? ['image/jpeg', 'image/png', 'image/apng', 'image/gif', 'image/webp', 'image/avif', 'video/mp4', 'video/webm'] : undefined,
8080
excludeNsfw: this.filter === 'excludeNsfw',
8181
excludeSfw: this.filter === 'excludeSfw',
82-
}, false, false).then((notes: any[]) => {
82+
}, false, !this.$store.getters.isSignedIn).then((notes: any[]) => {
8383
this.notes = notes;
8484
this.fetching = false;
8585

src/client/app/desktop/views/home/note.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default Vue.extend({
3535
3636
this.$root.api('notes/show', {
3737
noteId: this.$route.params.note
38-
}).then(note => {
38+
}, false, !this.$store.getters.isSignedIn).then(note => {
3939
if (this.$store.state.i || !note.user.host) this.note = note;
4040
}).catch((e: any) => {
4141
this.$root.dialog({

src/client/app/desktop/views/home/search.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default Vue.extend({
3232
limit: limit + 1,
3333
offset: cursor ? cursor : undefined,
3434
query: this.q
35-
}).then(notes => {
35+
}, false, !this.$store.getters.isSignedIn).then(notes => {
3636
if (notes.length == limit + 1) {
3737
notes.pop();
3838
return {

src/client/app/desktop/views/home/tag.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ export default Vue.extend({
1919
data() {
2020
return {
2121
connection: null,
22-
makePromise: cursor => this.$root.api('notes/search_by_tag', {
22+
makePromise: cursor => this.$root.api('notes/search-by-tag', {
2323
limit: limit + 1,
2424
offset: cursor ? cursor : undefined,
2525
tag: this.$route.params.tag
26-
}).then(notes => {
26+
}, false, !this.$store.getters.isSignedIn).then(notes => {
2727
if (notes.length == limit + 1) {
2828
notes.pop();
2929
return {

src/client/app/desktop/views/home/timeline.core.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default Vue.extend({
5959
};
6060
6161
if (this.src == 'tag') {
62-
this.endpoint = 'notes/search_by_tag';
62+
this.endpoint = 'notes/search-by-tag';
6363
this.query = {
6464
query: this.tagTl.query
6565
};

src/client/app/desktop/views/home/user/index.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export default Vue.extend({
4545
if (!this.$route.params.user) return;
4646
this.fetching = true;
4747
Progress.start();
48-
this.$root.api('users/show', parseAcct(this.$route.params.user)).then(user => {
48+
const { username, host } = parseAcct(this.$route.params.user);
49+
this.$root.api('users/show', { username, host: host ?? undefined }, false, !this.$store.getters.isSignedIn).then(user => {
4950
if (this.$store.state.i || !user.host) this.user = user;
5051
this.fetching = false;
5152
Progress.done();

src/client/app/desktop/views/home/user/user.home.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ export default Vue.extend({
4747
},
4848
data() {
4949
return {
50-
makeFrequentlyRepliedUsersPromise: () => this.$root.api('users/get_frequently_replied_users', {
50+
makeFrequentlyRepliedUsersPromise: () => this.$root.api('users/get-frequently-replied-users', {
5151
userId: this.user.id
52-
}).then(res => res.map(x => x.user)),
52+
}, false, !this.$store.getters.isSignedIn).then(res => res.map(x => x.user)),
5353
};
5454
},
5555
methods: {

src/client/app/desktop/views/home/user/user.photos.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default Vue.extend({
4242
fileType: image,
4343
excludeNsfw: !this.$store.state.device.alwaysShowNsfw,
4444
limit: 9,
45-
}).then(notes => {
45+
}, false, !this.$store.getters.isSignedIn).then(notes => {
4646
for (const note of notes) {
4747
for (const file of note.files) {
4848
file._note = note;

src/client/app/desktop/views/home/user/user.timeline.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default Vue.extend({
5252
withFiles: this.mode == 'with-media',
5353
untilId: (!this.date && cursor) ? cursor : undefined,
5454
untilDate: this.date ? this.date.getTime() : undefined,
55-
}).then((notes: ThinPackedNote[]) => {
55+
}, false, !this.$store.getters.isSignedIn).then((notes: ThinPackedNote[]) => {
5656
this.date = null;
5757
if (notes.length == fetchLimit + 1) {
5858
notes.pop();

src/client/app/desktop/views/pages/welcome.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export default Vue.extend({
192192
fileType: image,
193193
limit: 6,
194194
excludeNsfw: true,
195-
}, false, false).then((notes: any[]) => {
195+
}, false, true).then((notes: any[]) => {
196196
const files = concat(notes.map((n: any): any[] => n.files));
197197
this.photos = files.filter(f => image.includes(f.type)).slice(0, 6);
198198
});

src/client/app/mobile/views/components/note-detail.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export default Vue.extend({
156156
this.$root.api('notes/children', {
157157
noteId: this.appearNote.id,
158158
limit: 30
159-
}).then(replies => {
159+
}, false, !this.$store.getters.isSignedIn).then(replies => {
160160
this.replies = replies;
161161
});
162162
},

src/client/app/mobile/views/components/user-timeline.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default Vue.extend({
2525
limit: fetchLimit + 1,
2626
withFiles: this.withMedia,
2727
untilId: cursor ? cursor : undefined,
28-
}).then(notes => {
28+
}, false, !this.$store.getters.isSignedIn).then(notes => {
2929
if (notes.length == fetchLimit + 1) {
3030
notes.pop();
3131
return {

src/client/app/mobile/views/pages/featured.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default Vue.extend({
8484
fileType: this.mediaOnly ? ['image/jpeg', 'image/png', 'image/apng', 'image/gif', 'image/webp', 'image/avif', 'video/mp4', 'video/webm'] : undefined,
8585
excludeNsfw: this.filter === 'excludeNsfw',
8686
excludeSfw: this.filter === 'excludeSfw',
87-
}, false, false).then((notes: any) => {
87+
}, false, !this.$store.getters.isSignedIn).then((notes: any) => {
8888
notes.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
8989
this.notes = notes;
9090
this.fetching = false;

src/client/app/mobile/views/pages/home.timeline.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default Vue.extend({
6060
};
6161
6262
if (this.src == 'tag') {
63-
this.endpoint = 'notes/search_by_tag';
63+
this.endpoint = 'notes/search-by-tag';
6464
this.query = {
6565
query: this.tagTl.query
6666
};

src/client/app/mobile/views/pages/note.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default Vue.extend({
4242
4343
this.$root.api('notes/show', {
4444
noteId: this.$route.params.note
45-
}).then(note => {
45+
}, false, !this.$store.getters.isSignedIn).then(note => {
4646
this.note = note;
4747
}).catch((e: any) => {
4848
this.$root.dialog({

src/client/app/mobile/views/pages/search.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default Vue.extend({
3030
limit: limit + 1,
3131
offset: cursor ? cursor : undefined,
3232
query: this.q
33-
}).then(notes => {
33+
}, false, !this.$store.getters.isSignedIn).then(notes => {
3434
if (notes.length == limit + 1) {
3535
notes.pop();
3636
return {

src/client/app/mobile/views/pages/tag.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export default Vue.extend({
3232
data() {
3333
return {
3434
connection: null,
35-
makePromise: cursor => this.$root.api('notes/search_by_tag', {
35+
makePromise: cursor => this.$root.api('notes/search-by-tag', {
3636
limit: limit + 1,
3737
offset: cursor ? cursor : undefined,
3838
tag: this.$route.params.tag
39-
}).then(notes => {
39+
}, false, !this.$store.getters.isSignedIn).then(notes => {
4040
if (notes.length == limit + 1) {
4141
notes.pop();
4242
return {

src/client/app/mobile/views/pages/user/home.notes.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default Vue.extend({
2323
mounted() {
2424
this.$root.api('users/notes', {
2525
userId: this.user.id,
26-
}).then(notes => {
26+
}, false, !this.$store.getters.isSignedIn).then(notes => {
2727
this.notes = notes;
2828
this.fetching = false;
2929
});

src/client/app/mobile/views/pages/user/home.photos.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default Vue.extend({
3333
fileType: image,
3434
excludeNsfw: !this.$store.state.device.alwaysShowNsfw,
3535
limit: 9,
36-
}).then(notes => {
36+
}, false, !this.$store.getters.isSignedIn).then(notes => {
3737
for (const note of notes) {
3838
for (const media of note.files) {
3939
if (this.images.length < 9) {

src/client/app/mobile/views/pages/user/home.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export default Vue.extend({
4242
props: ['user'],
4343
data() {
4444
return {
45-
makeFrequentlyRepliedUsersPromise: () => this.$root.api('users/get_frequently_replied_users', {
45+
makeFrequentlyRepliedUsersPromise: () => this.$root.api('users/get-frequently-replied-users', {
4646
userId: this.user.id
47-
}).then(res => res.map(x => x.user)),
47+
}, false, !this.$store.getters.isSignedIn).then(res => res.map(x => x.user)),
4848
};
4949
}
5050
});

src/client/app/mobile/views/pages/user/index.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ export default Vue.extend({
141141
fetch() {
142142
Progress.start();
143143
144-
this.$root.api('users/show', parseAcct(this.$route.params.user)).then(user => {
144+
const { username, host } = parseAcct(this.$route.params.user);
145+
146+
this.$root.api('users/show', { username, host: host ?? undefined }, false, !this.$store.getters.isSignedIn).then(user => {
145147
if (this.$store.state.i || !user.host) this.user = user;
146148
this.fetching = false;
147149

src/client/app/mobile/views/pages/welcome.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default Vue.extend({
8686
fileType: image,
8787
limit: 6,
8888
excludeNsfw: true,
89-
}, false, false).then((notes: any[]) => {
89+
}, false, true).then((notes: any[]) => {
9090
const files = concat(notes.map((n: any): any[] => n.files));
9191
this.photos = files.filter(f => image.includes(f.type)).slice(0, 6);
9292
});

src/server/api/call.ts

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ export default async (endpoint: string, user: IUser | null | undefined, app: IAp
105105
reason: `cannot cast to ${param.validator.name}`,
106106
})
107107
}
108+
} else if (param.validator.name === 'Array' && typeof data[k] === 'string') {
109+
data[k] = (data[k] as string).split(',');
108110
}
109111
}
110112
}

src/server/api/endpoints/hashtags/list.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export const meta = {
66
tags: ['hashtags'],
77

88
requireCredential: false,
9+
allowGet: true,
10+
cacheSec: 600,
911

1012
params: {
1113
limit: {

src/server/api/endpoints/notes/children.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export const meta = {
1414
tags: ['notes'],
1515

1616
requireCredential: false,
17+
allowGet: true,
18+
cacheSec: 60,
1719

1820
params: {
1921
noteId: {

src/server/api/endpoints/notes/featured.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const meta = {
1616
requireCredential: false,
1717

1818
allowGet: true,
19+
cacheSec: 600,
1920

2021
params: {
2122
minScore: {

src/server/api/endpoints/notes/search-by-tag.ts

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export const meta = {
1616

1717
tags: ['notes', 'hashtags'],
1818

19+
requireCredential: false,
20+
allowGet: true,
21+
cacheSec: 60,
22+
1923
params: {
2024
tag: {
2125
validator: $.optional.str,

src/server/api/endpoints/notes/search.ts

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export const meta = {
2424
tags: ['notes'],
2525

2626
requireCredential: false,
27+
allowGet: true,
28+
cacheSec: 60,
2729

2830
params: {
2931
query: {

src/server/api/endpoints/notes/show.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export const meta = {
1616
tags: ['notes'],
1717

1818
requireCredential: false,
19+
allowGet: true,
20+
cacheSec: 60,
1921

2022
params: {
2123
noteId: {

src/server/api/endpoints/stats.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const meta = {
77
requireCredential: false,
88

99
allowGet: true,
10+
cacheSec: 600,
1011
canDenyPost: true,
1112

1213
desc: {

src/server/api/endpoints/users/get-frequently-replied-users.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export const meta = {
1212
tags: ['users'],
1313

1414
requireCredential: false,
15+
allowGet: true,
16+
cacheSec: 3600 * 24,
1517

1618
params: {
1719
userId: {

src/server/api/endpoints/users/notes.ts

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export const meta = {
1313

1414
tags: ['users', 'notes'],
1515

16+
requireCredential: false,
17+
allowGet: true,
18+
cacheSec: 60,
19+
1620
params: {
1721
userId: {
1822
validator: $.type(ID),

src/server/api/endpoints/users/show.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export const meta = {
1616
tags: ['users'],
1717

1818
requireCredential: false,
19+
allowGet: true,
20+
cacheSec: 60,
1921

2022
params: {
2123
userId: {

src/server/web/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ router.get('/assets/*', async ctx => {
8282
// Apple touch icon
8383
router.get('/apple-touch-icon.png', async ctx => {
8484
await send(ctx as any, '/assets/apple-touch-icon.png', {
85-
root: client
85+
root: client,
86+
maxage: ms('7 days'),
8687
});
8788
});
8889

0 commit comments

Comments
 (0)