Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove asyncComputed from MergeTable #8388

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
getRecords on created
  • Loading branch information
RayBB committed Oct 6, 2023
commit d8b74d9c5bc9e21c1cd5702f33b8bcf6e0989e72
47 changes: 26 additions & 21 deletions openlibrary/components/MergeUI/MergeTable.vue
Original file line number Diff line number Diff line change
@@ -75,30 +75,20 @@ export default {
},
data() {
return {
// /** @type {{[key: string]: Boolean}} */
// selected: []
records: []
};
},
created(){
this.getRecords();
},
props: {
olids: Array,
show_diffs: Boolean,
primary: String
},
asyncComputed: {
async records() {
const olids_sorted = _.sortBy(this.olids, olid =>
parseFloat(olid.match(/\d+/)[0])
);
// Ensure orphaned editions are at the bottom of the list
const records = _.orderBy(
await Promise.all(olids_sorted.map(fetchRecord)),
record => record.type.key, 'desc');

return records;
},

async editions() {
if (!this.records) return null;
if (!this.recordsExist) return null;

const editionPromises = await Promise.all(
this.records.map(r => r.type.key.includes('work') ? get_editions(r.key) : {size: 0})
@@ -117,7 +107,7 @@ export default {
},

async lists() {
if (!this.records) return null;
if (!this.recordsExist) return null;

// We only need the count, so set limit=0 (waaaay faster!)
const promises = await Promise.all(
@@ -129,7 +119,7 @@ export default {
);
},
async bookshelves() {
if (!this.records) return null;
if (!this.recordsExist) return null;

const promises = await Promise.all(
this.records.map(r => (r.type.key === '/type/work') ? get_bookshelves(r.key) : {})
@@ -141,7 +131,7 @@ export default {
},

async ratings() {
if (!this.records) return null;
if (!this.recordsExist) return null;

const promises = await Promise.all(
this.records.map(r => (r.type.key === '/type/work') ? get_ratings(r.key) : {})
@@ -158,20 +148,35 @@ export default {
return field in this.merge.sources
? this.merge.sources[field].includes(record.key)
: record.key === this.master_key;
},
async getRecords(){
// gets records from api and sets them
const olids_sorted = _.sortBy(this.olids, olid =>
parseFloat(olid.match(/\d+/)[0])
);
// Ensure orphaned editions are at the bottom of the list
const records = _.orderBy(
await Promise.all(olids_sorted.map(fetchRecord)),
record => record.type.key, 'desc');

this.records = records;
}
},
computed: {
recordsExist(){
return this.records && this.records.length > 1;
},
selected(){
/** @type {{[key: string]: Boolean}} */
/*
Maybe this and master_key shouldn't be computed since they only matter on first one.
But I think that it's okay since this.records will never change.
*/
if (!this.records) return []
if (!this.recordsExist) return []
return _.fromPairs(this.records.map(record => [record.key, record.type.key.includes('work')]));
},
master_key(){
if (!this.records) return null
if (!this.recordsExist) return null

let masterIndex = 0;
if (this.primary) {
@@ -237,7 +242,7 @@ export default {
];
},
merge(){
if (!this.master_key || !this.records || !this.editions)
if (!this.master_key || !this.recordsExist || !this.editions)
return undefined;

const master = this.records.find(r => r.key === this.master_key);