Remove obsolete IndexedDB operations from web UI (#14730)
Storing objects in IndexedDB was disabled in #7932, but we were still trying to read objects from it before making an API callremotes/1727458204337373841/tmp_refs/heads/signup-info-prompt
parent
68d3b160de
commit
a6121a159c
|
@ -1,6 +1,5 @@
|
||||||
import api, { getLinks } from '../api';
|
import api, { getLinks } from '../api';
|
||||||
import openDB from '../storage/db';
|
import { importFetchedAccount, importFetchedAccounts } from './importer';
|
||||||
import { importAccount, importFetchedAccount, importFetchedAccounts } from './importer';
|
|
||||||
|
|
||||||
export const ACCOUNT_FETCH_REQUEST = 'ACCOUNT_FETCH_REQUEST';
|
export const ACCOUNT_FETCH_REQUEST = 'ACCOUNT_FETCH_REQUEST';
|
||||||
export const ACCOUNT_FETCH_SUCCESS = 'ACCOUNT_FETCH_SUCCESS';
|
export const ACCOUNT_FETCH_SUCCESS = 'ACCOUNT_FETCH_SUCCESS';
|
||||||
|
@ -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_SUCCESS = 'FOLLOW_REQUEST_REJECT_SUCCESS';
|
||||||
export const FOLLOW_REQUEST_REJECT_FAIL = 'FOLLOW_REQUEST_REJECT_FAIL';
|
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) {
|
export function fetchAccount(id) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch(fetchRelationships([id]));
|
dispatch(fetchRelationships([id]));
|
||||||
|
|
||||||
if (getState().getIn(['accounts', id], null) !== null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch(fetchAccountRequest(id));
|
dispatch(fetchAccountRequest(id));
|
||||||
|
|
||||||
openDB().then(db => getFromDB(
|
api(getState).get(`/api/v1/accounts/${id}`).then(response => {
|
||||||
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 => {
|
|
||||||
dispatch(importFetchedAccount(response.data));
|
dispatch(importFetchedAccount(response.data));
|
||||||
})).then(() => {
|
|
||||||
dispatch(fetchAccountSuccess());
|
dispatch(fetchAccountSuccess());
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(fetchAccountFail(id, error));
|
dispatch(fetchAccountFail(id, error));
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import api from '../api';
|
import api from '../api';
|
||||||
import openDB from '../storage/db';
|
|
||||||
import { evictStatus } from '../storage/modifier';
|
|
||||||
|
|
||||||
import { deleteFromTimelines } from './timelines';
|
import { deleteFromTimelines } from './timelines';
|
||||||
import { importFetchedStatus, importFetchedStatuses, importAccount, importStatus, importFetchedAccount } from './importer';
|
import { importFetchedStatus, importFetchedStatuses, importFetchedAccount } from './importer';
|
||||||
import { ensureComposeIsVisible } from './compose';
|
import { ensureComposeIsVisible } from './compose';
|
||||||
|
|
||||||
export const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST';
|
export const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST';
|
||||||
|
@ -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) {
|
export function fetchStatus(id) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const skipLoading = getState().getIn(['statuses', id], null) !== null;
|
const skipLoading = getState().getIn(['statuses', id], null) !== null;
|
||||||
|
@ -94,23 +50,10 @@ export function fetchStatus(id) {
|
||||||
|
|
||||||
dispatch(fetchStatusRequest(id, skipLoading));
|
dispatch(fetchStatusRequest(id, skipLoading));
|
||||||
|
|
||||||
openDB().then(db => {
|
api(getState).get(`/api/v1/statuses/${id}`).then(response => {
|
||||||
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 => {
|
|
||||||
dispatch(importFetchedStatus(response.data));
|
dispatch(importFetchedStatus(response.data));
|
||||||
dispatch(fetchStatusSuccess(skipLoading));
|
dispatch(fetchStatusSuccess(skipLoading));
|
||||||
})).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(fetchStatusFail(id, error, skipLoading));
|
dispatch(fetchStatusFail(id, error, skipLoading));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -152,7 +95,6 @@ export function deleteStatus(id, routerHistory, withRedraft = false) {
|
||||||
dispatch(deleteStatusRequest(id));
|
dispatch(deleteStatusRequest(id));
|
||||||
|
|
||||||
api(getState).delete(`/api/v1/statuses/${id}`).then(response => {
|
api(getState).delete(`/api/v1/statuses/${id}`).then(response => {
|
||||||
evictStatus(id);
|
|
||||||
dispatch(deleteStatusSuccess(id));
|
dispatch(deleteStatusSuccess(id));
|
||||||
dispatch(deleteFromTimelines(id));
|
dispatch(deleteFromTimelines(id));
|
||||||
dispatch(importFetchedAccount(response.data.account));
|
dispatch(importFetchedAccount(response.data.account));
|
||||||
|
|
Loading…
Reference in New Issue