Skip to content

Commit

Permalink
Remove obsolete IndexedDB operations from web UI (mastodon#14730)
Browse files Browse the repository at this point in the history
Storing objects in IndexedDB was disabled in mastodon#7932, but we were
still trying to read objects from it before making an API call
  • Loading branch information
Gargron authored Sep 4, 2020
1 parent 68d3b16 commit a6121a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 96 deletions.
37 changes: 2 additions & 35 deletions app/javascript/mastodon/actions/accounts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import api, { getLinks } from '../api';
import openDB from '../storage/db';
import { importAccount, importFetchedAccount, importFetchedAccounts } from './importer';
import { importFetchedAccount, importFetchedAccounts } from './importer';

export const ACCOUNT_FETCH_REQUEST = 'ACCOUNT_FETCH_REQUEST';
export const ACCOUNT_FETCH_SUCCESS = 'ACCOUNT_FETCH_SUCCESS';
Expand Down Expand Up @@ -74,45 +73,13 @@ export const FOLLOW_REQUEST_REJECT_REQUEST = 'FOLLOW_REQUEST_REJECT_REQUEST';
export const FOLLOW_REQUEST_REJECT_SUCCESS = 'FOLLOW_REQUEST_REJECT_SUCCESS';
export const FOLLOW_REQUEST_REJECT_FAIL = 'FOLLOW_REQUEST_REJECT_FAIL';

function getFromDB(dispatch, getState, index, id) {
return new Promise((resolve, reject) => {
const request = index.get(id);

request.onerror = reject;

request.onsuccess = () => {
if (!request.result) {
reject();
return;
}

dispatch(importAccount(request.result));
resolve(request.result.moved && getFromDB(dispatch, getState, index, request.result.moved));
};
});
}

export function fetchAccount(id) {
return (dispatch, getState) => {
dispatch(fetchRelationships([id]));

if (getState().getIn(['accounts', id], null) !== null) {
return;
}

dispatch(fetchAccountRequest(id));

openDB().then(db => getFromDB(
dispatch,
getState,
db.transaction('accounts', 'read').objectStore('accounts').index('id'),
id,
).then(() => db.close(), error => {
db.close();
throw error;
})).catch(() => api(getState).get(`/api/v1/accounts/${id}`).then(response => {
api(getState).get(`/api/v1/accounts/${id}`).then(response => {
dispatch(importFetchedAccount(response.data));
})).then(() => {
dispatch(fetchAccountSuccess());
}).catch(error => {
dispatch(fetchAccountFail(id, error));
Expand Down
64 changes: 3 additions & 61 deletions app/javascript/mastodon/actions/statuses.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import api from '../api';
import openDB from '../storage/db';
import { evictStatus } from '../storage/modifier';

import { deleteFromTimelines } from './timelines';
import { importFetchedStatus, importFetchedStatuses, importAccount, importStatus, importFetchedAccount } from './importer';
import { importFetchedStatus, importFetchedStatuses, importFetchedAccount } from './importer';
import { ensureComposeIsVisible } from './compose';

export const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST';
Expand Down Expand Up @@ -40,48 +38,6 @@ export function fetchStatusRequest(id, skipLoading) {
};
};

function getFromDB(dispatch, getState, accountIndex, index, id) {
return new Promise((resolve, reject) => {
const request = index.get(id);

request.onerror = reject;

request.onsuccess = () => {
const promises = [];

if (!request.result) {
reject();
return;
}

dispatch(importStatus(request.result));

if (getState().getIn(['accounts', request.result.account], null) === null) {
promises.push(new Promise((accountResolve, accountReject) => {
const accountRequest = accountIndex.get(request.result.account);

accountRequest.onerror = accountReject;
accountRequest.onsuccess = () => {
if (!request.result) {
accountReject();
return;
}

dispatch(importAccount(accountRequest.result));
accountResolve();
};
}));
}

if (request.result.reblog && getState().getIn(['statuses', request.result.reblog], null) === null) {
promises.push(getFromDB(dispatch, getState, accountIndex, index, request.result.reblog));
}

resolve(Promise.all(promises));
};
});
}

export function fetchStatus(id) {
return (dispatch, getState) => {
const skipLoading = getState().getIn(['statuses', id], null) !== null;
Expand All @@ -94,23 +50,10 @@ export function fetchStatus(id) {

dispatch(fetchStatusRequest(id, skipLoading));

openDB().then(db => {
const transaction = db.transaction(['accounts', 'statuses'], 'read');
const accountIndex = transaction.objectStore('accounts').index('id');
const index = transaction.objectStore('statuses').index('id');

return getFromDB(dispatch, getState, accountIndex, index, id).then(() => {
db.close();
}, error => {
db.close();
throw error;
});
}).then(() => {
dispatch(fetchStatusSuccess(skipLoading));
}, () => api(getState).get(`/api/v1/statuses/${id}`).then(response => {
api(getState).get(`/api/v1/statuses/${id}`).then(response => {
dispatch(importFetchedStatus(response.data));
dispatch(fetchStatusSuccess(skipLoading));
})).catch(error => {
}).catch(error => {
dispatch(fetchStatusFail(id, error, skipLoading));
});
};
Expand Down Expand Up @@ -152,7 +95,6 @@ export function deleteStatus(id, routerHistory, withRedraft = false) {
dispatch(deleteStatusRequest(id));

api(getState).delete(`/api/v1/statuses/${id}`).then(response => {
evictStatus(id);
dispatch(deleteStatusSuccess(id));
dispatch(deleteFromTimelines(id));
dispatch(importFetchedAccount(response.data.account));
Expand Down

0 comments on commit a6121a1

Please sign in to comment.