diff --git a/packages/backend/native-utils/scylla-migration/cql/1689400417034_timeline/up.cql b/packages/backend/native-utils/scylla-migration/cql/1689400417034_timeline/up.cql index 8d7ce87018..99603a3fa4 100644 --- a/packages/backend/native-utils/scylla-migration/cql/1689400417034_timeline/up.cql +++ b/packages/backend/native-utils/scylla-migration/cql/1689400417034_timeline/up.cql @@ -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 diff --git a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts index 03ce0a0401..df4c90f173 100644 --- a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts @@ -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 })),