Skip to content

Commit f58b8b3

Browse files
committed
minor fixes
1 parent e4d8686 commit f58b8b3

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

create_db.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@ cd "$(dirname "$0")"
33
rm -rf dist/data
44
mkdir -p dist/data
55
cat create_db.sql | sqlite3 -cmd '.echo on' dist/data/db.sqlite3
6+
lastUpdated="$(sqlite3 dist/data/db.sqlite3 'select max(published) from videoData')"
7+
68
bytes="$(stat --printf="%s" dist/data/db.sqlite3)"
79
serverChunkSize=$((50 * 1024 * 1024))
810
suffixLength=3
911
split dist/data/db.sqlite3 --bytes=$serverChunkSize dist/data/db.sqlite3. --suffix-length=$suffixLength --numeric-suffixes
1012
rm dist/data/db.sqlite3
11-
echo '{"requestChunkSize": 4096, "databaseLengthBytes": '$bytes', "serverChunkSize": '$serverChunkSize', "urlPrefix": "db.sqlite3.", "suffixLength": '$suffixLength'}' > dist/data/config.json
13+
echo '
14+
{
15+
"requestChunkSize": 4096,
16+
"lastUpdated": '$lastUpdated',
17+
"databaseLengthBytes": '$bytes',
18+
"serverChunkSize": '$serverChunkSize',
19+
"urlPrefix": "db.sqlite3.",
20+
"suffixLength": '$suffixLength'
21+
}
22+
' > dist/data/config.json

src/UI.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import createPlotlyComponent from "react-plotly.js/factory";
1616
import Plotly from "plotly.js/lib/core";
1717
import { textChangeRangeIsUnchanged } from "typescript";
1818

19-
2019
const Plot = createPlotlyComponent(Plotly);
2120

2221
function formatDuration(sec_num: number) {
@@ -90,11 +89,15 @@ function formatBytes(b: number) {
9089
return b + "B";
9190
}
9291

93-
const SqliteStats: React.FC<{ stats: SqliteStats }> = observer(({ stats }) => {
92+
const SqliteStats: React.FC<{
93+
stats: SqliteStats;
94+
lastUpdated: number;
95+
}> = observer(({ stats, lastUpdated }) => {
9496
return (
9597
<>
9698
Sqlite stats: fetched {formatBytes(stats.totalFetchedBytes)} in{" "}
97-
{stats.totalRequests} requests (DB size: {formatBytes(stats.totalBytes)})
99+
{stats.totalRequests} requests (DB size: {formatBytes(stats.totalBytes)},
100+
updated: {new Date(lastUpdated * 1000).toLocaleDateString()})
98101
</>
99102
);
100103
});
@@ -107,7 +110,7 @@ const VideoMetaDisplay: React.FC<{ video: SponsorInfo }> = observer(
107110
<img
108111
src={video.meta.maxresdefault_thumbnail}
109112
width={200}
110-
style={{ float: "left" }}
113+
style={{ float: "left", margin: "0.5em" }}
111114
></img>
112115
<h4>{video.meta.title}</h4>
113116
</a>
@@ -139,6 +142,8 @@ export class UI extends React.Component {
139142
@observable
140143
stats: SqliteStats | null = null;
141144
@observable
145+
dbConfig: { lastUpdated: number } | null = null;
146+
@observable
142147
focussedVideo: SponsorInfo | null = null;
143148
@observable searchInput: string = "";
144149

@@ -147,7 +152,7 @@ export class UI extends React.Component {
147152
this.init();
148153
makeObservable(this);
149154
}
150-
interval: number = 0;
155+
interval: any = 0;
151156
componentDidMount() {
152157
this.interval = setInterval(async () => {
153158
this.stats = (await this.worker?.getStats()) || null;
@@ -157,10 +162,11 @@ export class UI extends React.Component {
157162
clearInterval(this.interval);
158163
}
159164
async init() {
160-
this.initState = "connectingToDb";
165+
this.initState = "connectingToDb";
161166
const res = await createDbWorker();
162167
this.db = res.db;
163168
this.worker = res.worker;
169+
this.dbConfig = res.config;
164170
const initialAuthor = new URLSearchParams(location.search).get("uploader");
165171
if (initialAuthor) this.setAuthor(initialAuthor);
166172
this.initState = "";
@@ -199,7 +205,7 @@ export class UI extends React.Component {
199205
setFocussed = (e: SponsorInfo) => (this.focussedVideo = e);
200206

201207
render() {
202-
if(this.initState) return <div>{this.initState}</div>;
208+
if (this.initState) return <div>{this.initState}</div>;
203209
return (
204210
<div>
205211
<div>
@@ -211,7 +217,7 @@ export class UI extends React.Component {
211217
loadOptions={this.authorsSearchDebounce}
212218
getOptionLabel={(e) => e.name}
213219
getOptionValue={(e) => e.name}
214-
onChange={(e) => this.setAuthor(e.name)}
220+
onChange={(e) => e && this.setAuthor(e.name)}
215221
/>
216222
</div>
217223
{this.data.state === "noinput" ? (
@@ -227,9 +233,19 @@ export class UI extends React.Component {
227233
<SponsorPlot data={this.data.segs} onHover={this.setFocussed} />
228234
</div>
229235
)}
230-
{this.focussedVideo && <VideoMetaDisplay video={this.focussedVideo} />}
236+
{this.focussedVideo && <>Selected video: <VideoMetaDisplay video={this.focussedVideo} /></>}
231237
<footer style={{ marginTop: "5em", color: "gray" }}>
232-
{this.stats ? <SqliteStats stats={this.stats} /> : ""}{" "}
238+
<div>{this.stats ? (
239+
<SqliteStats
240+
stats={this.stats}
241+
lastUpdated={this.dbConfig.lastUpdated}
242+
/>
243+
) : (
244+
""
245+
)}{" "}
246+
</div>
247+
<div>Source Code: <a href="https://github.com/phiresky/youtube-sponsorship-stats/">https://github.com/phiresky/youtube-sponsorship-stats/</a></div>
248+
233249
</footer>
234250
</div>
235251
);

src/db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function createDbWorker() {
3535
`Chunk size does not match page size: pragma page_size = ${pageSize} but chunkSize = ${chunkSize}`
3636
);
3737

38-
return { worker: sqlite, db };
38+
return { config, worker: sqlite, db };
3939
}
4040

4141
async function testLoop(metaDb: Database) {

src/sqlite.worker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ async function init() {
3434
}
3535
const sqljs = init();
3636
export type SplitFileConfig = {
37+
lastUpdated: number;
3738
urlPrefix: string;
3839
serverChunkSize: number;
3940
databaseLengthBytes: number;

0 commit comments

Comments
 (0)