fix clustering order

This commit is contained in:
Namekuji 2023-08-12 04:00:46 -04:00
parent 030294a10d
commit 86ccb51fd0
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532
2 changed files with 5 additions and 3 deletions

View file

@ -114,7 +114,8 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS global_timeline AS
AND "userId" IS NOT NULL
AND "userHost" IS NOT NULL
AND "visibility" = 'public'
PRIMARY KEY ("createdAtDate", "createdAt", "userId", "userHost", "visibility");
PRIMARY KEY ("createdAtDate", "createdAt", "userId", "userHost", "visibility")
WITH CLUSTERING ORDER BY ("createdAt" DESC);
CREATE MATERIALIZED VIEW IF NOT EXISTS local_timeline AS
SELECT * FROM note
@ -123,7 +124,8 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS local_timeline AS
AND "userId" IS NOT NULL
AND "userHost" = 'local'
AND "visibility" = 'public'
PRIMARY KEY ("createdAtDate", "createdAt", "userId", "userHost", "visibility");
PRIMARY KEY ("createdAtDate", "createdAt", "userId", "userHost", "visibility")
WITH CLUSTERING ORDER BY ("createdAt" DESC);
CREATE TABLE IF NOT EXISTS home_timeline (
"feedUserId" ascii, -- For partitioning

View file

@ -172,7 +172,7 @@ export default define(meta, paramDef, async (ps, user) => {
execNotePaginationQuery("local", ps, filter),
]);
const foundNotes = [...homeFoundNotes, ...localFoundNotes]
.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime())
.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime()) // Descendent
.slice(0, ps.limit * 1.5); // Some may be filtered out by Notes.packMany, thus we take more than ps.limit.
foundPacked.push(
...(await Notes.packMany(foundNotes, user, { scyllaNote: true })),