Skip to content

Commit

Permalink
Merge branch 'default' into auto-leave-booth
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Feb 16, 2024
2 parents c2cea59 + 925f34e commit e22e2c1
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions@1.4
- uses: superfly/flyctl-actions@1.5
with:
args: deploy
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-ns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Dispatch
runs-on: ubuntu-latest
steps:
- uses: peter-evans/repository-dispatch@v2
- uses: peter-evans/repository-dispatch@v3
with:
repository: u-wave/federation
token: ${{secrets.SCHEMA_ACCESS_TOKEN}}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org/).

## 0.5.0-alpha.19 / 06 Feb 2024
This is an alpha release, but new servers should use this version rather than an older "stable" one.

Features:
* Improve `/api/booth/history` performance. (#605, 49cb49c)

## 0.5.0-alpha.17 / 01 Dec 2023
This is an alpha release, but new servers should use this version rather than an older "stable" one.

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "u-wave-core",
"version": "0.5.0-alpha.17",
"version": "0.5.0-alpha.19",
"description": "The üWave core library.",
"license": "MIT",
"repository": "u-wave/core",
Expand Down Expand Up @@ -57,7 +57,7 @@
"passport-google-oauth20": "^2.0.0",
"passport-local": "^1.0.0",
"pino": "^8.0.0",
"pino-http": "^8.0.1",
"pino-http": "^9.0.0",
"qs": "^6.9.1",
"random-string": "^0.2.0",
"ratelimiter": "^3.4.0",
Expand Down Expand Up @@ -101,7 +101,7 @@
"@types/ws": "^8.2.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"c8": "^8.0.0",
"c8": "^9.0.0",
"concat-stream": "^2.0.0",
"delay": "^6.0.0",
"dotenv": "^16.0.0",
Expand Down
10 changes: 6 additions & 4 deletions src/errors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,18 @@ function createErrorClass(name, {
: string;

const Error = class extends base {
static code = code;

code = code;

name = name;

/** @param {TData} [data] */
constructor(data) {
// @ts-expect-error TS2345 This is actually unsafe but the generic TData type
// is hard to express correctly in JSDoc.
const i18nKey = getString(data);
super(t(i18nKey, data ?? {}) ?? undefined);
this.name = name;
this.code = code;
this.i18nKey = i18nKey;
this.data = data;
// http-errors overwrites the prototype of the error, so it will
Expand All @@ -102,8 +106,6 @@ function createErrorClass(name, {
}
};

Error.code = code;

return Error;
}

Expand Down
43 changes: 35 additions & 8 deletions src/plugins/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class HistoryRepository {
}

/**
* @param {object} filter
* @param {object|null} filter
* @param {{ offset?: number, limit?: number }} [pagination]
* @returns {Promise<Page<PopulatedHistoryEntry, { offset: number, limit: number }>>}
*/
Expand All @@ -43,12 +43,39 @@ class HistoryRepository {
MAX_PAGE_SIZE,
);

const total = await HistoryEntry.where(filter).countDocuments();
const query = HistoryEntry.where(filter)
.sort({ playedAt: -1 })
.skip(offset)
.limit(limit)
.populate('media.media user');
const total = filter != null
? await HistoryEntry.where(filter).countDocuments()
: await HistoryEntry.estimatedDocumentCount();
/** @type {import('mongoose').PipelineStage[]} */
const aggregate = [];
if (filter != null) {
aggregate.push({ $match: filter });
}
aggregate.push(
{ $sort: { playedAt: -1 } },
{ $skip: offset },
{ $limit: limit },
{
$lookup: {
from: 'media',
localField: 'media.media',
foreignField: '_id',
as: 'media.media',
},
},
{ $unwind: '$media.media' },
{
$lookup: {
from: 'users',
localField: 'user',
foreignField: '_id',
as: 'user',
},
},
{ $unwind: '$user' },
{ $project: { __v: 0, 'media.media.__v': 0, 'user.__v': 0 } },
);
const query = HistoryEntry.aggregate(aggregate);

/** @type {PopulatedHistoryEntry[]} */
const results = /** @type {any} */ (await query);
Expand All @@ -69,7 +96,7 @@ class HistoryRepository {
* @param {{ offset?: number, limit?: number }} [pagination]
*/
getRoomHistory(pagination = {}) {
return this.getHistory({}, pagination);
return this.getHistory(null, pagination);
}

/**
Expand Down

0 comments on commit e22e2c1

Please sign in to comment.