mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feature: add collections section - query optimization
This commit is contained in:
parent
b7cabfdbde
commit
2a6e0f31df
5 changed files with 51 additions and 46 deletions
|
@ -6,14 +6,12 @@ import {
|
||||||
UpdateDateColumn,
|
UpdateDateColumn,
|
||||||
OneToOne,
|
OneToOne,
|
||||||
JoinColumn,
|
JoinColumn,
|
||||||
ManyToMany,
|
|
||||||
} from "typeorm";
|
} from "typeorm";
|
||||||
import { Repack } from "./repack.entity";
|
import { Repack } from "./repack.entity";
|
||||||
|
|
||||||
import type { GameShop, GameStatus } from "@types";
|
import type { GameShop, GameStatus } from "@types";
|
||||||
import { Downloader } from "@shared";
|
import { Downloader } from "@shared";
|
||||||
import type { DownloadQueue } from "./download-queue.entity";
|
import type { DownloadQueue } from "./download-queue.entity";
|
||||||
import { Collection } from "./collection.entity";
|
|
||||||
|
|
||||||
@Entity("game")
|
@Entity("game")
|
||||||
export class Game {
|
export class Game {
|
||||||
|
@ -81,9 +79,6 @@ export class Game {
|
||||||
@OneToOne("DownloadQueue", "game")
|
@OneToOne("DownloadQueue", "game")
|
||||||
downloadQueue: DownloadQueue;
|
downloadQueue: DownloadQueue;
|
||||||
|
|
||||||
@ManyToMany("Collection", "games")
|
|
||||||
collections: Collection[];
|
|
||||||
|
|
||||||
@Column("boolean", { default: false })
|
@Column("boolean", { default: false })
|
||||||
isDeleted: boolean;
|
isDeleted: boolean;
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,11 @@ import { registerEvent } from "../register-event";
|
||||||
const getCollections = async () =>
|
const getCollections = async () =>
|
||||||
collectionRepository.find({
|
collectionRepository.find({
|
||||||
relations: {
|
relations: {
|
||||||
|
games: true,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
games: {
|
games: {
|
||||||
downloadQueue: true,
|
id: true,
|
||||||
repack: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
order: {
|
order: {
|
||||||
|
|
|
@ -8,7 +8,6 @@ const getLibrary = async () =>
|
||||||
},
|
},
|
||||||
relations: {
|
relations: {
|
||||||
downloadQueue: true,
|
downloadQueue: true,
|
||||||
collections: true,
|
|
||||||
},
|
},
|
||||||
order: {
|
order: {
|
||||||
createdAt: "desc",
|
createdAt: "desc",
|
||||||
|
|
|
@ -49,11 +49,8 @@ export function Sidebar() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
updateLibrary();
|
updateLibrary();
|
||||||
}, [lastPacket?.game.id, updateLibrary]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
updateCollections();
|
updateCollections();
|
||||||
});
|
}, [lastPacket?.game.id, updateLibrary, updateCollections]);
|
||||||
|
|
||||||
const isDownloading = sortedLibrary.some(
|
const isDownloading = sortedLibrary.some(
|
||||||
(game) => game.status === "active" && game.progress !== 1
|
(game) => game.status === "active" && game.progress !== 1
|
||||||
|
@ -85,9 +82,16 @@ export function Sidebar() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFilteredLibrary(
|
setFilteredLibrary(
|
||||||
sortedLibrary.filter((game) => !game.collections.length)
|
sortedLibrary.filter(
|
||||||
|
(game) =>
|
||||||
|
!collections.some((collection) =>
|
||||||
|
collection.games.some(
|
||||||
|
(collectionGame) => collectionGame.id == game.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}, [sortedLibrary]);
|
}, [sortedLibrary, collections]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.onmousemove = (event: MouseEvent) => {
|
window.onmousemove = (event: MouseEvent) => {
|
||||||
|
@ -216,39 +220,45 @@ export function Sidebar() {
|
||||||
</small>
|
</small>
|
||||||
|
|
||||||
<ul className={styles.menu}>
|
<ul className={styles.menu}>
|
||||||
{collection.games.map((game) => (
|
{sortedLibrary
|
||||||
<li
|
.filter((game) =>
|
||||||
key={game.id}
|
collection.games.some(
|
||||||
className={styles.menuItem({
|
(collectionGame) => game.id == collectionGame.id
|
||||||
active:
|
)
|
||||||
location.pathname ===
|
)
|
||||||
`/game/${game.shop}/${game.objectID}`,
|
.map((game) => (
|
||||||
muted: game.status === "removed",
|
<li
|
||||||
})}
|
key={game.id}
|
||||||
>
|
className={styles.menuItem({
|
||||||
<button
|
active:
|
||||||
type="button"
|
location.pathname ===
|
||||||
className={styles.menuItemButton}
|
`/game/${game.shop}/${game.objectID}`,
|
||||||
onClick={(event) =>
|
muted: game.status === "removed",
|
||||||
handleSidebarGameClick(event, game)
|
})}
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{game.iconUrl ? (
|
<button
|
||||||
<img
|
type="button"
|
||||||
className={styles.gameIcon}
|
className={styles.menuItemButton}
|
||||||
src={game.iconUrl}
|
onClick={(event) =>
|
||||||
alt={game.title}
|
handleSidebarGameClick(event, game)
|
||||||
/>
|
}
|
||||||
) : (
|
>
|
||||||
<SteamLogo className={styles.gameIcon} />
|
{game.iconUrl ? (
|
||||||
)}
|
<img
|
||||||
|
className={styles.gameIcon}
|
||||||
|
src={game.iconUrl}
|
||||||
|
alt={game.title}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<SteamLogo className={styles.gameIcon} />
|
||||||
|
)}
|
||||||
|
|
||||||
<span className={styles.menuItemButtonLabel}>
|
<span className={styles.menuItemButtonLabel}>
|
||||||
{getGameTitle(game)}
|
{getGameTitle(game)}
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
) : null
|
) : null
|
||||||
|
|
|
@ -128,7 +128,6 @@ export interface Game {
|
||||||
objectID: string;
|
objectID: string;
|
||||||
shop: GameShop;
|
shop: GameShop;
|
||||||
downloadQueue: DownloadQueue | null;
|
downloadQueue: DownloadQueue | null;
|
||||||
collections: Collection[];
|
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue