-
-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Platform fetch performance improvements #857
Changes from 3 commits
66510c0
c3fe8d7
8a1b7df
0922e5e
6735be4
fffc954
e72a1d8
9fc8267
9991922
eff0967
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from sqlalchemy import Column, Integer, String, select, func | ||
from sqlalchemy.orm import Mapped, relationship, column_property | ||
|
||
from models.base import BaseModel | ||
from models.rom import Rom | ||
from models.firmware import Firmware | ||
from sqlalchemy import Column, Integer, String | ||
from sqlalchemy.orm import Mapped, relationship | ||
|
||
|
||
class Platform(BaseModel): | ||
|
@@ -24,11 +25,9 @@ class Platform(BaseModel): | |
"Firmware", lazy="selectin", back_populates="platform" | ||
) | ||
|
||
@property | ||
def rom_count(self) -> int: | ||
from handler.database import db_platform_handler | ||
|
||
return db_platform_handler.get_rom_count(self.id) | ||
rom_count = column_property( | ||
select(func.count(Rom.id)).where(Rom.platform_id == id).scalar_subquery() | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Significantly faster since it runs in SQL land instead of making another DB query |
||
|
||
def __repr__(self) -> str: | ||
return self.name |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,36 @@ | ||
import axios from "axios"; | ||
import cookie from "js-cookie"; | ||
|
||
import router from "@/plugins/router"; | ||
import { debounce } from "lodash"; | ||
|
||
const api = axios.create({ baseURL: "/api", timeout: 120000 }); | ||
|
||
const inflightRequests = new Set(); | ||
|
||
const networkQuiesced = debounce(() => { | ||
document.dispatchEvent(new CustomEvent("network-quiesced")); | ||
}, 300); | ||
|
||
// Set CSRF header for all requests | ||
api.interceptors.request.use((config) => { | ||
inflightRequests.add(config.url); | ||
networkQuiesced.cancel(); | ||
|
||
config.headers["x-csrftoken"] = cookie.get("csrftoken"); | ||
return config; | ||
}); | ||
|
||
api.interceptors.response.use( | ||
(response) => response, | ||
(response) => { | ||
inflightRequests.delete(response.config.url); | ||
|
||
// If there are no more inflight requests, fetch home data | ||
if (inflightRequests.size === 0) { | ||
networkQuiesced(); | ||
} | ||
|
||
return response; | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does what it says; fires a custom event when all network requests are complete, which triggers loading things like the platforms sidebar and heartbeat data. |
||
(error) => { | ||
if (error.response?.status === 403) { | ||
router.push({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer needed since as it turns out performance is unaffected by loading firmware data as well