delete individual blob files for completed file downloads to save space #234

Merged
akinwale merged 3 commits from blob-delete into master 2018-08-17 20:11:16 +02:00
5 changed files with 55 additions and 16 deletions

View file

@ -27,6 +27,7 @@ import {
TextInput,
ToastAndroid
} from 'react-native';
import { doDeleteCompleteBlobs } from '../redux/actions/file';
skhameneh commented 2018-08-17 17:08:10 +02:00 (Migrated from github.com)
Review

Replace the relative path with an alias or a build resolve

Replace the relative path with an alias or a build resolve
import { SETTINGS, doHideNotification, doNotify, selectNotification } from 'lbry-redux';
import {
doUserEmailVerify,
@ -227,6 +228,7 @@ class AppWithNavigationState extends React.Component {
}
_handleAppStateChange = (nextAppState) => {
const { dispatch } = this.props;
// Check if the app was suspended
if (AppState.currentState && AppState.currentState.match(/inactive|background/)) {
AsyncStorage.getItem('firstLaunchTime').then(start => {
@ -237,6 +239,11 @@ class AppWithNavigationState extends React.Component {
}
});
}
if (AppState.currentState && AppState.currentState.match(/active/)) {
// Cleanup blobs for completed files upon app resume to save space
dispatch(doDeleteCompleteBlobs());
}
}
_handleUrl = (evt) => {

View file

@ -4,6 +4,7 @@ const Constants = {
SETTING_ALPHA_UNDERSTANDS_RISKS: "alphaUnderstandRisks",
ACTION_DELETE_COMPLETED_BLOBS: "DELETE_COMPLETED_BLOBS",
ACTION_FIRST_RUN_PAGE_CHANGED: "FIRST_RUN_PAGE_CHANGED",
};

View file

@ -8,6 +8,7 @@ import {
skhameneh commented 2018-08-17 17:09:00 +02:00 (Migrated from github.com)
Review

Replace the relative path with an alias or a build resolve

Replace the relative path with an alias or a build resolve
skhameneh commented 2018-08-17 17:09:00 +02:00 (Migrated from github.com)
Review

Replace the relative path with an alias or a build resolve

Replace the relative path with an alias or a build resolve
selectUser,
selectEmailToVerify
} from 'lbryinc';
import { doDeleteCompleteBlobs } from '../../redux/actions/file';
skhameneh commented 2018-08-17 17:09:00 +02:00 (Migrated from github.com)
Review

Replace the relative path with an alias or a build resolve

Replace the relative path with an alias or a build resolve
import SplashScreen from './view';
const select = state => ({
@ -17,6 +18,7 @@ const select = state => ({
skhameneh commented 2018-08-17 17:09:00 +02:00 (Migrated from github.com)
Review

Replace the relative path with an alias or a build resolve

Replace the relative path with an alias or a build resolve
skhameneh commented 2018-08-17 17:09:00 +02:00 (Migrated from github.com)
Review

Replace the relative path with an alias or a build resolve

Replace the relative path with an alias or a build resolve
const perform = dispatch => ({
authenticate: (appVersion, deviceId) => dispatch(doAuthenticate(appVersion, deviceId)),
deleteCompleteBlobs: () => dispatch(doDeleteCompleteBlobs()),
skhameneh commented 2018-08-17 17:09:00 +02:00 (Migrated from github.com)
Review

Replace the relative path with an alias or a build resolve

Replace the relative path with an alias or a build resolve
balanceSubscribe: () => dispatch(doBalanceSubscribe()),
notify: data => dispatch(doNotify(data)),
setEmailToVerify: email => dispatch(doUserEmailToVerify(email)),

skhameneh commented 2018-08-17 17:09:00 +02:00 (Migrated from github.com)
Review

Replace the relative path with an alias or a build resolve

Replace the relative path with an alias or a build resolve
skhameneh commented 2018-08-17 17:09:00 +02:00 (Migrated from github.com)
Review

Replace the relative path with an alias or a build resolve

Replace the relative path with an alias or a build resolve

View file

@ -117,10 +117,13 @@ class SplashScreen extends React.PureComponent {
}
_updateStatusCallback(status) {
const { deleteCompleteBlobs } = this.props;
const startupStatus = status.startup_status;
// At the minimum, wallet should be started and blocks_behind equal to 0 before calling resolve
const hasStarted = startupStatus.wallet && status.wallet.blocks_behind <= 0;
if (hasStarted) {
deleteCompleteBlobs();
// Wait until we are able to resolve a name before declaring
// that we are done.
// TODO: This is a hack, and the logic should live in the daemon

View file

@ -10,6 +10,7 @@ import {
selectDownloadingByOutpoint,
} from 'lbry-redux';
import { Alert, NativeModules } from 'react-native';
import Constants from '../../constants';
skhameneh commented 2018-08-17 17:09:12 +02:00 (Migrated from github.com)
Review

Replace the relative path with an alias or a build resolve

Replace the relative path with an alias or a build resolve
const DOWNLOAD_POLL_INTERVAL = 250;
@ -41,13 +42,17 @@ export function doUpdateLoadStatus(uri, outpoint) {
NativeModules.LbryDownloadManager.updateDownload(uri, fileInfo.file_name, 100, writtenBytes, totalBytes);
}
// Once a download has been completed, delete the individual blob files to save space
Lbry.blob_list({ sd_hash: fileInfo.sd_hash }).then(hashes => {
hashes.forEach(hash => {
Lbry.blob_delete({ blob_hash: hash });
});
});
/*const notif = new window.Notification('LBRY Download Complete', {
body: fileInfo.metadata.stream.metadata.title,
silent: false,
});
notif.onclick = () => {
ipcRenderer.send('focusWindow', 'main');
};*/
});*/
} else {
// ready to play
const { total_bytes: totalBytes, written_bytes: writtenBytes } = fileInfo;
@ -301,3 +306,24 @@ export function doDeleteFile(outpoint, deleteFromComputer, abandonClaim) {
//setProgressBar(totalProgress);
};
}
export function doDeleteCompleteBlobs() {
return dispatch => {
dispatch({
type: Constants.ACTION_DELETE_COMPLETED_BLOBS,
data: {},
});
Lbry.file_list().then(files => {
files.forEach(fileInfo => {
if (fileInfo.completed) {
Lbry.blob_list({ sd_hash: fileInfo.sd_hash }).then(hashes => {
hashes.forEach(hash => {
Lbry.blob_delete({ blob_hash: hash });
});
});
}
});
});
};
}