fix: filter featured notes via origin
This commit is contained in:
parent
2c4c569773
commit
e6df07afb0
3 changed files with 37 additions and 20 deletions
|
@ -76,7 +76,7 @@ CREATE TABLE note ( -- Store all posts
|
||||||
"reactions" map<text, int>, -- Reactions
|
"reactions" map<text, int>, -- Reactions
|
||||||
"noteEdit" set<frozen<note_edit_history>>, -- Edit History
|
"noteEdit" set<frozen<note_edit_history>>, -- Edit History
|
||||||
"updatedAt" timestamp,
|
"updatedAt" timestamp,
|
||||||
PRIMARY KEY ("createdAtDate", "createdAt", "userId", "userHost", "visibility", "score")
|
PRIMARY KEY ("createdAtDate", "createdAt", "userId", "userHost", "visibility")
|
||||||
) WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
) WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
||||||
|
|
||||||
CREATE INDEX note_by_uri ON note ("uri");
|
CREATE INDEX note_by_uri ON note ("uri");
|
||||||
|
@ -91,8 +91,7 @@ CREATE MATERIALIZED VIEW note_by_id AS
|
||||||
AND "userId" IS NOT NULL
|
AND "userId" IS NOT NULL
|
||||||
AND "userHost" IS NOT NULL
|
AND "userHost" IS NOT NULL
|
||||||
AND "visibility" IS NOT NULL
|
AND "visibility" IS NOT NULL
|
||||||
AND "score" IS NOT NULL
|
PRIMARY KEY ("id", "createdAt", "createdAtDate", "userId", "userHost", "visibility")
|
||||||
PRIMARY KEY ("id", "createdAt", "createdAtDate", "userId", "userHost", "visibility", "score")
|
|
||||||
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
||||||
|
|
||||||
CREATE MATERIALIZED VIEW note_by_user_id AS
|
CREATE MATERIALIZED VIEW note_by_user_id AS
|
||||||
|
@ -102,8 +101,7 @@ CREATE MATERIALIZED VIEW note_by_user_id AS
|
||||||
AND "createdAtDate" IS NOT NULL
|
AND "createdAtDate" IS NOT NULL
|
||||||
AND "userHost" IS NOT NULL
|
AND "userHost" IS NOT NULL
|
||||||
AND "visibility" IS NOT NULL
|
AND "visibility" IS NOT NULL
|
||||||
AND "score" IS NOT NULL
|
PRIMARY KEY ("userId", "createdAt", "createdAtDate", "userHost", "visibility")
|
||||||
PRIMARY KEY ("userId", "createdAt", "createdAtDate", "userHost", "visibility", "score")
|
|
||||||
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
||||||
|
|
||||||
CREATE MATERIALIZED VIEW note_by_renote_id AS
|
CREATE MATERIALIZED VIEW note_by_renote_id AS
|
||||||
|
@ -114,8 +112,7 @@ CREATE MATERIALIZED VIEW note_by_renote_id AS
|
||||||
AND "userId" IS NOT NULL
|
AND "userId" IS NOT NULL
|
||||||
AND "userHost" IS NOT NULL
|
AND "userHost" IS NOT NULL
|
||||||
AND "visibility" IS NOT NULL
|
AND "visibility" IS NOT NULL
|
||||||
AND "score" IS NOT NULL
|
PRIMARY KEY ("renoteId", "createdAt", "createdAtDate", "userId", "userHost", "visibility")
|
||||||
PRIMARY KEY ("renoteId", "createdAt", "createdAtDate", "userId", "userHost", "visibility", "score")
|
|
||||||
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
||||||
|
|
||||||
CREATE MATERIALIZED VIEW note_by_renote_id_and_user_id AS
|
CREATE MATERIALIZED VIEW note_by_renote_id_and_user_id AS
|
||||||
|
@ -126,8 +123,7 @@ CREATE MATERIALIZED VIEW note_by_renote_id_and_user_id AS
|
||||||
AND "userId" IS NOT NULL
|
AND "userId" IS NOT NULL
|
||||||
AND "userHost" IS NOT NULL
|
AND "userHost" IS NOT NULL
|
||||||
AND "visibility" IS NOT NULL
|
AND "visibility" IS NOT NULL
|
||||||
AND "score" IS NOT NULL
|
PRIMARY KEY (("renoteId", "userId"), "createdAt", "createdAtDate", "userHost", "visibility")
|
||||||
PRIMARY KEY (("renoteId", "userId"), "createdAt", "createdAtDate", "userHost", "visibility", "score")
|
|
||||||
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
||||||
|
|
||||||
CREATE MATERIALIZED VIEW note_by_channel_id AS
|
CREATE MATERIALIZED VIEW note_by_channel_id AS
|
||||||
|
@ -138,8 +134,7 @@ CREATE MATERIALIZED VIEW note_by_channel_id AS
|
||||||
AND "userId" IS NOT NULL
|
AND "userId" IS NOT NULL
|
||||||
AND "userHost" IS NOT NULL
|
AND "userHost" IS NOT NULL
|
||||||
AND "visibility" IS NOT NULL
|
AND "visibility" IS NOT NULL
|
||||||
AND "score" IS NOT NULL
|
PRIMARY KEY ("channelId", "createdAt", "createdAtDate", "userId", "userHost", "visibility")
|
||||||
PRIMARY KEY ("channelId", "createdAt", "createdAtDate", "userId", "userHost", "visibility", "score")
|
|
||||||
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
||||||
|
|
||||||
CREATE MATERIALIZED VIEW global_timeline AS
|
CREATE MATERIALIZED VIEW global_timeline AS
|
||||||
|
@ -148,9 +143,8 @@ CREATE MATERIALIZED VIEW global_timeline AS
|
||||||
AND "createdAt" IS NOT NULL
|
AND "createdAt" IS NOT NULL
|
||||||
AND "userId" IS NOT NULL
|
AND "userId" IS NOT NULL
|
||||||
AND "userHost" IS NOT NULL
|
AND "userHost" IS NOT NULL
|
||||||
AND "score" IS NOT NULL
|
|
||||||
AND "visibility" = 'public'
|
AND "visibility" = 'public'
|
||||||
PRIMARY KEY ("createdAtDate", "createdAt", "userId", "userHost", "visibility", "score")
|
PRIMARY KEY ("createdAtDate", "createdAt", "userId", "userHost", "visibility")
|
||||||
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
||||||
|
|
||||||
CREATE MATERIALIZED VIEW local_timeline AS
|
CREATE MATERIALIZED VIEW local_timeline AS
|
||||||
|
@ -160,8 +154,7 @@ CREATE MATERIALIZED VIEW local_timeline AS
|
||||||
AND "userId" IS NOT NULL
|
AND "userId" IS NOT NULL
|
||||||
AND "userHost" = 'local'
|
AND "userHost" = 'local'
|
||||||
AND "visibility" = 'public'
|
AND "visibility" = 'public'
|
||||||
AND "score" IS NOT NULL
|
PRIMARY KEY ("createdAtDate", "createdAt", "userId", "userHost", "visibility")
|
||||||
PRIMARY KEY ("createdAtDate", "createdAt", "userId", "userHost", "visibility", "score")
|
|
||||||
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
WITH CLUSTERING ORDER BY ("createdAt" DESC);
|
||||||
|
|
||||||
CREATE MATERIALIZED VIEW score_feed AS
|
CREATE MATERIALIZED VIEW score_feed AS
|
||||||
|
@ -172,8 +165,8 @@ CREATE MATERIALIZED VIEW score_feed AS
|
||||||
AND "userHost" IS NOT NULL
|
AND "userHost" IS NOT NULL
|
||||||
AND "score" IS NOT NULL
|
AND "score" IS NOT NULL
|
||||||
AND "visibility" = 'public'
|
AND "visibility" = 'public'
|
||||||
AND "score" > 0
|
AND "score" IS NOT NULL
|
||||||
PRIMARY KEY ("createdAtDate", "score", "userHost", "createdAt", "userId", "visibility")
|
PRIMARY KEY ("createdAtDate", "score", "createdAt", "userHost", "userId", "visibility")
|
||||||
WITH CLUSTERING ORDER BY ("score" DESC, "createdAt" DESC);
|
WITH CLUSTERING ORDER BY ("score" DESC, "createdAt" DESC);
|
||||||
|
|
||||||
CREATE TABLE home_timeline (
|
CREATE TABLE home_timeline (
|
||||||
|
|
|
@ -144,7 +144,7 @@ export const scyllaQueries = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
scoreFeed: {
|
scoreFeed: {
|
||||||
select: `SELECT * FROM score_feed WHERE "createdAtDate" = ?`,
|
select: `SELECT * FROM score_feed WHERE "createdAtDate" = ? AND "score" > 0`,
|
||||||
},
|
},
|
||||||
reaction: {
|
reaction: {
|
||||||
insert: `INSERT INTO reaction
|
insert: `INSERT INTO reaction
|
||||||
|
|
|
@ -92,15 +92,39 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
.execute(prepared.scoreFeed.select, [targetDay], { prepare: true })
|
.execute(prepared.scoreFeed.select, [targetDay], { prepare: true })
|
||||||
.then((result) => result.rows.map(parseScyllaNote));
|
.then((result) => result.rows.map(parseScyllaNote));
|
||||||
|
|
||||||
|
switch (ps.origin) {
|
||||||
|
case "local":
|
||||||
|
notes = notes.filter((note) => !note.userHost);
|
||||||
|
break;
|
||||||
|
case "remote":
|
||||||
|
notes = notes.filter((note) => !!note.userHost);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
notes = await filterMutedUser(notes, user, mutedUserIds, mutedInstances);
|
notes = await filterMutedUser(
|
||||||
|
notes,
|
||||||
|
user,
|
||||||
|
mutedUserIds,
|
||||||
|
mutedInstances,
|
||||||
|
);
|
||||||
notes = await filterMutedNote(notes, user, mutedWords);
|
notes = await filterMutedNote(notes, user, mutedWords);
|
||||||
notes = await filterBlockUser(notes, user, [...blockerIds, ...blockingIds]);
|
notes = await filterBlockUser(notes, user, [
|
||||||
|
...blockerIds,
|
||||||
|
...blockingIds,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
foundNotes.push(...notes);
|
foundNotes.push(...notes);
|
||||||
targetDay = new Date(targetDay.getTime() - ONEDAY);
|
targetDay = new Date(targetDay.getTime() - ONEDAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Notes.packMany(
|
||||||
|
foundNotes
|
||||||
|
.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())
|
||||||
|
.slice(ps.offset, ps.offset + ps.limit),
|
||||||
|
user,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = Notes.createQueryBuilder("note")
|
const query = Notes.createQueryBuilder("note")
|
||||||
|
|
Loading…
Reference in a new issue