5 Commits

Author SHA1 Message Date
slasherss 22ebbd2399 added fuzzy searching and caching 2026-05-10 19:28:23 +02:00
slasherss e5f9e737b2 feat: Updated angular
Reviewed-on: #7
2026-04-30 11:36:01 +02:00
slasherss 1e58cf9a94 changed method privacy 2026-04-30 11:31:11 +02:00
slasherss a324b0b5b3 updated angular material 2026-04-30 11:15:10 +02:00
slasherss af09103b8e updated angular core 2026-04-30 11:14:24 +02:00
10 changed files with 2411 additions and 2074 deletions
+14
View File
@@ -15,6 +15,7 @@
"connect-mongo": "^5.0.0",
"cors": "^2.8.5",
"express": "^4.18.2",
"fuse.js": "^7.3.0",
"mongoose": "^7.4.1",
"multer": "^2.0.2",
"node-schedule": "^2.1.1",
@@ -1950,6 +1951,19 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/fuse.js": {
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-7.3.0.tgz",
"integrity": "sha512-plz8RVjfcDedTGfVngWH1jmJvBvAwi1v2jecfDerbEnMcmOYUEEwKFTHbNoCiYyzaK2Ws8lABkTCcRSqCY1q4w==",
"license": "Apache-2.0",
"engines": {
"node": ">=10"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/krisk"
}
},
"node_modules/get-intrinsic": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
+1
View File
@@ -17,6 +17,7 @@
"connect-mongo": "^5.0.0",
"cors": "^2.8.5",
"express": "^4.18.2",
"fuse.js": "^7.3.0",
"mongoose": "^7.4.1",
"multer": "^2.0.2",
"node-schedule": "^2.1.1",
+35
View File
@@ -0,0 +1,35 @@
import User, { IUser } from "@/schemas/User";
import Fuse, { FuseIndex } from "fuse.js";
import { Types } from "mongoose";
class CachedIndex {
private index: FuseIndex = null
private list: (IUser & { _id: Types.ObjectId; })[] = null
private fuse: Fuse<IUser & { _id: Types.ObjectId; }> = null
refresh() {
this.index = null
this.list = null
this.fuse = null
}
private async getIndex() {
return this.index || (this.index = Fuse.createIndex(['uname', 'fname', 'surname', 'room'], await this.getList()))
}
private async getList() {
return this.list || (this.list = await User.find({}, { uname: 1, fname: 1, surname: 1, room: 1 }))
}
private async getFuse(): Promise<typeof this.fuse> {
return this.fuse || (this.fuse = new Fuse(await this.getList(), {
keys: ['uname', 'fname', 'surname', 'room']
}, await this.getIndex()))
}
async search(q: string) {
return (await this.getFuse()).search(q, { limit: 5 }).map(r => r.item)
}
}
export default new CachedIndex()
+2 -2
View File
@@ -8,9 +8,9 @@ import { notifRouter } from "./notif";
import { keysRouter } from "./keys";
import { cleanRouter } from "./clean";
import { settingsRouter } from "./settings";
import User from "@/schemas/User";
import Group from "@/schemas/Group";
import usettings from "@/helpers/usettings";
import CachedIndex from "@/helpers/CachedIndex";
export const adminRouter = Router()
@@ -25,7 +25,7 @@ adminRouter.use('/clean', cleanRouter)
adminRouter.use('/settings', settingsRouter)
adminRouter.get('/usearch', async (req, res) => {
var results = await User.find({$text: {$search: req.query['q'].toString()}}, {uname: 1, surname: 1, fname: 1, room: 1})
var results = await CachedIndex.search(req.query['q'].toString())
res.send(results)
})
+3
View File
@@ -1,3 +1,4 @@
import CachedIndex from "@/helpers/CachedIndex";
import { Perms, project } from "@/utility";
import mongoose, { Types, Schema } from "mongoose"
@@ -29,6 +30,8 @@ const userSchema = new Schema<IUser>({
userSchema.index({uname: "text", room: "text", fname: "text", surname: "text"}, {weights: {fname: 3, surname: 4, room: 2, uname: 1}, default_language: "none"})
userSchema.post("save", () => {CachedIndex.refresh()})
export default mongoose.model("logins", userSchema)
export function userVisibleFields(user: IUser & {_id: mongoose.Types.ObjectId}): Pick<IUser, "fname" | "surname" | "uname" | "room"> & {_id: mongoose.Types.ObjectId} {
+2332 -2047
View File
File diff suppressed because it is too large Load Diff
+18 -18
View File
@@ -13,20 +13,20 @@
},
"private": true,
"dependencies": {
"@angular/animations": "^20.0.2",
"@angular/cdk": "^20.0.2",
"@angular/cli": "^20.3.18",
"@angular/common": "^20.3.14",
"@angular/compiler": "^20.3.16",
"@angular/core": "^20.3.17",
"@angular/forms": "^20.0.2",
"@angular/material": "^20.0.2",
"@angular/material-luxon-adapter": "^20.0.2",
"@angular/platform-browser": "^20.0.2",
"@angular/platform-browser-dynamic": "^20.0.2",
"@angular/router": "^20.0.2",
"@angular/service-worker": "^20.0.2",
"luxon": "^3.6.1",
"@angular/animations": "^21.2.11",
"@angular/cdk": "^21.2.9",
"@angular/cli": "^21.2.9",
"@angular/common": "^21.2.11",
"@angular/compiler": "^21.2.11",
"@angular/core": "^21.2.11",
"@angular/forms": "^21.2.11",
"@angular/material": "^21.2.9",
"@angular/material-luxon-adapter": "^21.2.9",
"@angular/platform-browser": "^21.2.11",
"@angular/platform-browser-dynamic": "^21.2.11",
"@angular/router": "^21.2.11",
"@angular/service-worker": "^21.2.11",
"luxon": "^3.7.2",
"marked": "^12.0.1",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
@@ -34,9 +34,9 @@
"zone.js": "~0.15.1"
},
"devDependencies": {
"@angular/build": "^20.0.1",
"@angular/compiler-cli": "^20.0.2",
"@angular/localize": "^20.0.2",
"@angular/build": "^21.2.9",
"@angular/compiler-cli": "^21.2.11",
"@angular/localize": "^21.2.11",
"@types/jasmine": "~4.3.0",
"@types/luxon": "^3.6.2",
"@types/underscore": "^1.13.0",
@@ -49,7 +49,7 @@
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"prettier": "3.5.3",
"typescript": "~5.8.3",
"typescript": "~5.9.3",
"typescript-eslint": "8.33.1"
}
}
@@ -59,7 +59,7 @@ export class UserSearchComponent
control: FormControl = new FormControl<UserSearchResult | string>("")
protected list: UserSearchResult[] = []
private _onChange!: (_: UserSearchResult) => void
private _onTouched!: () => void
protected _onTouched!: () => void
static nextId = 0
+4 -1
View File
@@ -1,10 +1,13 @@
import { provideZoneChangeDetection } from '@angular/core'
import { platformBrowser } from '@angular/platform-browser'
import { AppModule } from './app/app.module'
import { environment } from './environments/environment'
platformBrowser()
.bootstrapModule(AppModule)
.bootstrapModule(AppModule, {
applicationProviders: [provideZoneChangeDetection()],
})
.then(() => {
if ('serviceWorker' in navigator && environment.production) {
navigator.serviceWorker.register('./ngsw-worker.js')
+1 -5
View File
@@ -18,11 +18,7 @@
"importHelpers": true,
"target": "ES2022",
"module": "ES2022",
"useDefineForClassFields": false,
"lib": [
"ES2022",
"dom"
]
"useDefineForClassFields": false
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,