Skip to content

Commit a270372

Browse files
authored
Merge pull request #63 from gitcomteam/feature/62-performance-improvements
Feature/62 performance improvements
2 parents 1d95319 + ad12327 commit a270372

File tree

10 files changed

+122
-36
lines changed

10 files changed

+122
-36
lines changed

.env.example

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
REACT_APP_API_URL=http://localhost:8000
1+
REACT_APP_API_URL=http://localhost:8000
2+
3+
PUBLIC_URL=https://sdn-host.net/public/
4+
5+
CDN_HOST=some-ftp-host.com
6+
CDN_LOGIN=gitcom
7+
CDN_PASSWORD=your-password

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@
4646
"last 1 firefox version",
4747
"last 1 safari version"
4848
]
49-
}
49+
},
50+
"devDependencies": {}
5051
}

public/index.html

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,5 @@
2424

2525
gtag('config', 'UA-153205738-3');
2626
</script>
27-
28-
<!-- Start of Async Drift Code -->
29-
<script>
30-
"use strict";
31-
32-
!function () {
33-
var t = window.driftt = window.drift = window.driftt || [];
34-
if (!t.init) {
35-
if (t.invoked) return void (window.console && console.error && console.error("Drift snippet included twice."));
36-
t.invoked = !0, t.methods = ["identify", "config", "track", "reset", "debug", "show", "ping", "page", "hide", "off", "on"],
37-
t.factory = function (e) {
38-
return function () {
39-
var n = Array.prototype.slice.call(arguments);
40-
return n.unshift(e), t.push(n), t;
41-
};
42-
}, t.methods.forEach(function (e) {
43-
t[e] = t.factory(e);
44-
}), t.load = function (t) {
45-
var e = 3e5, n = Math.ceil(new Date() / e) * e, o = document.createElement("script");
46-
o.type = "text/javascript", o.async = !0, o.crossorigin = "anonymous", o.src = "https://js.driftt.com/include/" + n + "/" + t + ".js";
47-
var i = document.getElementsByTagName("script")[0];
48-
i.parentNode.insertBefore(o, i);
49-
};
50-
}
51-
}();
52-
drift.SNIPPET_VERSION = '0.3.1';
53-
drift.load('kmcg4ky4chmh');
54-
</script>
55-
<!-- End of Async Drift Code -->
5627
</body>
5728
</html>

public/js/lazy_init.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
!function () {
2+
var t = window.driftt = window.drift = window.driftt || [];
3+
if (!t.init) {
4+
if (t.invoked) return void (window.console && console.error && console.error("Drift snippet included twice."));
5+
t.invoked = !0, t.methods = ["identify", "config", "track", "reset", "debug", "show", "ping", "page", "hide", "off", "on"],
6+
t.factory = function (e) {
7+
return function () {
8+
var n = Array.prototype.slice.call(arguments);
9+
return n.unshift(e), t.push(n), t;
10+
};
11+
}, t.methods.forEach(function (e) {
12+
t[e] = t.factory(e);
13+
}), t.load = function (t) {
14+
var e = 3e5, n = Math.ceil(new Date() / e) * e, o = document.createElement("script");
15+
o.type = "text/javascript", o.async = !0, o.crossorigin = "anonymous", o.src = "https://js.driftt.com/include/" + n + "/" + t + ".js";
16+
var i = document.getElementsByTagName("script")[0];
17+
i.parentNode.insertBefore(o, i);
18+
};
19+
}
20+
}();
21+
drift.SNIPPET_VERSION = '0.3.1';
22+
drift.load('kmcg4ky4chmh');
23+
24+
window.dataLayer = window.dataLayer || [];
25+
function gtag(){dataLayer.push(arguments);}
26+
gtag('js', new Date());
27+
28+
gtag('config', 'UA-153205738-3');

scripts/deploy/prod/copy_build.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

scripts/deploy/prod/deploy.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/bin/bash
2-
rm -rf /usr/local/gitcom/frontend/app/build/*
3-
cp -avr /usr/local/gitcom/frontend/app/tmp/build /usr/local/gitcom/frontend/app/
2+
python3 scripts/deploy/prod/stages/cdn_upload.py
3+
./scripts/deploy/prod/stages/copy_build.sh $1
4+
ssh $1 "bash -s" < ./scripts/deploy/prod/stages/deploy.sh
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os.path, os
2+
from ftplib import FTP, error_perm
3+
4+
from dotenv import load_dotenv
5+
load_dotenv()
6+
7+
load_dotenv(verbose=True)
8+
9+
from pathlib import Path
10+
env_path = Path('.') / '.env'
11+
12+
host = os.getenv("CDN_HOST")
13+
port = 21
14+
15+
ftp = FTP()
16+
ftp.connect(host,port)
17+
ftp.login(os.getenv("CDN_LOGIN"), os.getenv("CDN_PASSWORD"))
18+
19+
def count_files(path):
20+
files_count = 0
21+
for name in os.listdir(path):
22+
localpath = os.path.join(path, name)
23+
if os.path.isfile(localpath):
24+
files_count += 1
25+
elif os.path.isdir(localpath):
26+
files_count += 1
27+
files_count += count_files(localpath)
28+
return files_count
29+
30+
def upload_folder(ftp, path, prefix = None):
31+
if prefix is not None:
32+
progress = 0
33+
print("total files: " + str(count_files(path)) + " in " + path)
34+
root_dir = "/gitcom/" + prefix
35+
try:
36+
ftp.mkd(root_dir)
37+
except error_perm as e:
38+
print(e)
39+
ftp.cwd(root_dir)
40+
41+
for name in os.listdir(path):
42+
localpath = os.path.join(path, name)
43+
if os.path.isfile(localpath):
44+
print("Storing ", name, localpath)
45+
ftp.storbinary('STOR ' + name, open(localpath,'rb'))
46+
elif os.path.isdir(localpath):
47+
print("MKD", name)
48+
49+
try:
50+
ftp.mkd(name)
51+
except error_perm as e:
52+
print(e)
53+
54+
print("CWD", name)
55+
ftp.cwd(name)
56+
upload_folder(ftp, localpath)
57+
print("CWD", "..")
58+
ftp.cwd("..")
59+
60+
upload_folder(ftp, "build", "public/")
61+
62+
ftp.quit()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
scp -r build "$1":/usr/local/gitcom/frontend/app/tmp
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
rm -rf /usr/local/gitcom/frontend/app/build/*
3+
cp -avr /usr/local/gitcom/frontend/app/tmp/build /usr/local/gitcom/frontend/app/

src/AppRoot.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ window.AppConfig = config;
1919
// @ts-ignore
2020
window.App = new App();
2121

22+
async function loadScriptAsync(url: string) {
23+
const script = document.createElement("script");
24+
25+
script.src = url;
26+
script.async = true;
27+
28+
document.body.appendChild(script);
29+
}
30+
31+
loadScriptAsync("https://momentjs.com/downloads/moment.min.js").then(() => {});
32+
33+
setTimeout(() => {
34+
loadScriptAsync("/js/lazy_init.js").then(() => {});
35+
}, 1000);
36+
2237
function AppRoot() {
2338
return (
2439
<div className="app">

0 commit comments

Comments
 (0)