Skip to content

Commit

Permalink
add incremental export
Browse files Browse the repository at this point in the history
  • Loading branch information
cs0x7f committed Aug 7, 2024
1 parent c690200 commit 2e8e09b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
33 changes: 31 additions & 2 deletions dist/userdata2.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@
}
} else if (isset($_POST['cnt'])) {
$sql = "SELECT `value_len` AS size,
`value_nsolv` AS nsolv,
unix_timestamp(`upload_time`) AS modifiedTime
FROM (
SELECT `value_len`, `upload_time` FROM `export_data` WHERE `uid` = '$uid'
SELECT `value_len`, `value_nsolv`, `upload_time` FROM `export_data` WHERE `uid` = '$uid'
UNION ALL
SELECT 0, `upload_time` FROM `export_data2` WHERE `uid` = '$uid'
SELECT 0, `value_nsolv`, `upload_time` FROM `export_data2` WHERE `uid` = '$uid'
) t1 ORDER BY `upload_time` DESC";
$ret = $db->query($sql);
if ($ret === false) {
Expand Down Expand Up @@ -103,6 +104,34 @@
} else {
echo '{"retcode":500,"reason":"db insert error"}';
}
} else if (isset($_POST['exists'])) {//EXISTS
if (!preg_match("/^[a-zA-Z0-9,]+$/", $_POST['exists'])) {
echo '{"retcode":400,"reason":"invalid ids"}';
exit(0);
}
$ids = explode(",", $_POST['exists'], 4096);
if (count($ids) >= 4096) {
echo '{"retcode":400,"reason":"invalid ids"}';
exit(0);
}
foreach ($ids as $id1) {
if (strlen($id1) >= 250 || strlen($id1) < 1) {
echo '{"retcode":400,"reason":"invalid ids"}';
exit(0);
}
}
$sql = "SELECT DISTINCT `uid` FROM `export_data2` WHERE `uid` in ('" . join("','", $ids) . "')";
$ret = $db->query($sql);
if ($ret === false) {
echo '{"retcode":500,"reason":"db select error"}';
exit(0);
}
$arr = array();
while($row = $ret->fetch_assoc()) {
$arr[] = $row['uid'];
}
error_log("[" . date("Y-m-d H:i:sO") . "] EXISTS $uid " . count($ids) . "\n", 3, CSTIMER_USERDATA_LOGFILE);
echo '{"retcode":0,"datas":' . json_encode($arr) . '}';
} else if (isset($_POST['ids'])) {//GETMUL
if (!preg_match("/^[a-zA-Z0-9,]+$/", $_POST['ids'])) {
echo '{"retcode":400,"reason":"invalid ids"}';
Expand Down
28 changes: 23 additions & 5 deletions src/js/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,35 @@ var exportFunc = execMain(function() {
function uploadData(id) {
return getLocalDataSliced(id).then(function(slices) {
var ids = [];
var datas = [];
//TODO check redaudant to reduce upload size
for (var key in slices) {
if (key == id) {
continue;
}
ids.push(key);
datas.push(slices[key]);
}
return $.ppost('https://cstimer.net/userdata2.php', {
'id': id,
'ids': ids.join(','),
'datas': datas.join(',')
'exists': ids.join(',')
}, 'json').then(function(val) {
if (val['retcode'] != 0) {
Promise.reject();
}
var exists = val['datas'];
var ids = [];
var datas = [];
for (var key in slices) {
if (exists.indexOf(key) != -1 && key != id) {
continue;
}
ids.push(key);
datas.push(slices[key]);
}
return $.ppost('https://cstimer.net/userdata2.php', {
'id': id,
'ids': ids.join(','),
'datas': datas.join(',')
}, 'json');
}).then(function(val) {
return val['retcode'] == 0 ? Promise.resolve() : Promise.reject();
});
});
Expand Down

0 comments on commit 2e8e09b

Please sign in to comment.