Skip to content

Commit

Permalink
Optimizations (#363)
Browse files Browse the repository at this point in the history
* fix(frontend): do not retry search failures

* feat(backend): configure background jobs interval

* build(backend): bump version

* fix(frontend): do not display number stats that are 0
  • Loading branch information
IgnisDa authored Sep 25, 2023
1 parent 6b7e86c commit 106fd5d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ryot"
version = "2.18.4"
version = "2.18.5"
edition = "2021"
repository = "https://github.com/IgnisDa/ryot"
license = "GPL-V3"
Expand Down
5 changes: 5 additions & 0 deletions apps/backend/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ pub struct ServerConfig {
pub insecure_cookie: bool,
/// This will set SameSite=None on the auth cookies.
pub samesite_none: bool,
/// The number of seconds after which a new application job is checked for.
/// Reducing this number will increase memory consumption but make certain
/// actions (eg: items automatically being added to "In Progress") faster.
#[setting(default = 5)]
pub application_job_check_seconds: u64,
/// The hours in which a media can be marked as seen again for a user. This
/// is used so that the same media can not be used marked as started when
/// it has been already marked as seen in the last `n` hours.
Expand Down
5 changes: 4 additions & 1 deletion apps/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ async fn main() -> Result<()> {
let user_cleanup_every = config.scheduler.user_cleanup_every;
let pull_every = config.integration.pull_every;
let max_file_size = config.server.max_file_size;
let new_background_job_check_seconds = config.server.application_job_check_seconds;
fs::write(
&config.server.config_dump_path,
serde_json::to_string_pretty(&config)?,
Expand Down Expand Up @@ -288,7 +289,9 @@ async fn main() -> Result<()> {
.layer(ApalisExtension(importer_service_1.clone()))
.layer(ApalisExtension(media_service_4.clone()))
.layer(ApalisExtension(exercise_service_1.clone()))
.with_storage(perform_application_job_storage.clone())
.with_storage_config(perform_application_job_storage.clone(), |cfg| {
cfg.fetch_interval(Duration::from_secs(new_background_job_check_seconds))
})
.build_fn(perform_application_job)
})
.run()
Expand Down
51 changes: 30 additions & 21 deletions apps/frontend/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ today.setHours(0, 0, 0, 0);
const UpComingMedia = ({ um }: { um: CalendarEventPartFragment }) => {
const diff = DateTime.fromISO(um.date).diff(DateTime.fromJSDate(today));
const numDaysLeft = parseInt(diff.as("days").toFixed(0));
console.log(diff.as("days").toFixed(0));

return (
<MediaItemWithoutUpdateModal
item={{
Expand Down Expand Up @@ -94,7 +94,12 @@ const UpComingMedia = ({ um }: { um: CalendarEventPartFragment }) => {
const ActualDisplayStat = (props: {
icon: JSX.Element;
lot: string;
data: { type: "duration" | "number"; label: string; value: number }[];
data: {
type: "duration" | "number";
label: string;
value: number;
hideIfZero?: true;
}[];
color?: string;
}) => {
const theme = useMantineTheme();
Expand All @@ -110,25 +115,27 @@ const ActualDisplayStat = (props: {
rootColor={props.color ?? colors[11]}
/>
<Flex wrap={"wrap"} ml="xs">
{props.data.map((d, idx) => (
<Box key={idx.toString()} mx={"xs"}>
<Text
fw={d.label !== "Runtime" ? "bold" : undefined}
display={"inline"}
fz={{ base: "md", md: "sm" }}
>
{d.type === "duration"
? humanizer.humanize(d.value * 1000 * 60, {
round: true,
largest: 3,
})
: humanFormat(d.value)}
</Text>
<Text display={"inline"} ml="4px" fz={{ base: "md", md: "sm" }}>
{d.label === "Runtime" ? "" : d.label}
</Text>
</Box>
))}
{props.data.map((d, idx) =>
d.type === "number" && d.value === 0 && d.hideIfZero ? undefined : (
<Box key={idx.toString()} mx={"xs"}>
<Text
fw={d.label !== "Runtime" ? "bold" : undefined}
display={"inline"}
fz={{ base: "md", md: "sm" }}
>
{d.type === "duration"
? humanizer.humanize(d.value * 1000 * 60, {
round: true,
largest: 3,
})
: humanFormat(d.value)}
</Text>
<Text display={"inline"} ml="4px" fz={{ base: "md", md: "sm" }}>
{d.label === "Runtime" ? "" : d.label}
</Text>
</Box>
),
)}
</Flex>
</Paper>
);
Expand Down Expand Up @@ -437,6 +444,7 @@ const Page: NextPageWithLayout = () => {
label: "Reviews",
value: latestUserSummary.data.media.reviewsPosted,
type: "number",
hideIfZero: true,
},
{
label: "People",
Expand All @@ -461,6 +469,7 @@ const Page: NextPageWithLayout = () => {
label: "Workouts",
value: latestUserSummary.data.fitness.workoutsRecorded,
type: "number",
hideIfZero: true,
},
]}
/>
Expand Down
2 changes: 2 additions & 0 deletions apps/frontend/src/pages/media/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const Page: NextPageWithLayout = () => {
return mediaList;
},
enabled: lot !== undefined && activeTab === "mine",
retry: false,
});
const collections = useQuery({
queryKey: ["collections"],
Expand Down Expand Up @@ -205,6 +206,7 @@ const Page: NextPageWithLayout = () => {
},
enabled: query !== "" && lot !== undefined && activeTab === "search",
staleTime: Infinity,
retry: false,
});

useEffect(() => {
Expand Down
7 changes: 7 additions & 0 deletions docs/includes/backend-config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ export interface SchedulerConfig {
}

export interface ServerConfig {
/**
* The number of seconds after which a new application job is checked for.
* Reducing this number will increase memory consumption but make certain
* actions (eg: items automatically being added to "In Progress") faster.
* @default 5
*/
application_job_check_seconds: number;
/** The path where the config file will be written once the server boots up. */
config_dump_path: string;
/** An array of URLs for CORS. */
Expand Down

0 comments on commit 106fd5d

Please sign in to comment.