Bugzilla – Attachment 147115 Details for
Bug 32807
No need to fetch all if we need to know if one exist
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32807: Fetch count instead of all entries for agreements and licenses
Bug-32807-Fetch-count-instead-of-all-entries-for-a.patch (text/plain), 8.38 KB, created by
Matt Blenkinsop
on 2023-02-22 10:00:38 UTC
(
hide
)
Description:
Bug 32807: Fetch count instead of all entries for agreements and licenses
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2023-02-22 10:00:38 UTC
Size:
8.38 KB
patch
obsolete
>From fd690251853a641f4395fc7ae912ecf179b7117e Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 22 Feb 2023 08:48:48 +0100 >Subject: [PATCH] Bug 32807: Fetch count instead of all entries for agreements > and licenses > >To list agreements and licenses we are retrieving the whole list to >simply know if at least one exists (and display the table that will >fetch the X first elements to display). > >We should call count instead. > >Test plan: >List agreements and licenses. >If none exists, the table is not displayed but a "There are no... >defined" message instead. >If at least one exists the table must be there > >Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >--- > .../js/vue/components/ERM/AgreementsList.vue | 20 +++++++++--------- > .../ERM/EHoldingsLocalPackagesList.vue | 2 +- > .../ERM/EHoldingsLocalTitlesList.vue | 2 +- > .../js/vue/components/ERM/LicensesList.vue | 16 +++++++------- > .../prog/js/vue/fetch/erm-api-client.js | 21 ++++++++++++++++++- > 5 files changed, 40 insertions(+), 21 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue >index 251c4c892a4..2d1a0c91494 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue >@@ -1,8 +1,8 @@ > <template> > <div v-if="!initialized">{{ $__("Loading") }}</div> >- <div v-else-if="agreements" id="agreements_list"> >+ <div v-else-if="agreement_count" id="agreements_list"> > <Toolbar v-if="before_route_entered" /> >- <fieldset v-if="agreements.length" class="filters"> >+ <fieldset v-if="agreement_count > 0" class="filters"> > <label for="expired_filter">{{ $__("Filter by expired") }}:</label> > <input > type="checkbox" >@@ -24,7 +24,7 @@ > :value="$__('Filter')" > /> > </fieldset> >- <div v-if="agreements.length" class="page-section"> >+ <div v-if="agreement_count > 0" class="page-section"> > <table :id="table_id"></table> > </div> > <div v-else-if="initialized" class="dialog message"> >@@ -66,7 +66,7 @@ export default { > data: function () { > return { > fp_config: flatpickr_defaults, >- agreements: [], >+ agreement_count: null, > initialized: false, > filters: { > by_expired: this.$route.query.by_expired || false, >@@ -82,7 +82,7 @@ export default { > vm.before_route_entered = true // FIXME This is ugly, but we need to distinguish when it's used as main component or child component (from EHoldingsEBSCOPAckagesShow for instance) > if (!vm.building_table) { > vm.building_table = true >- vm.getAgreements().then(() => vm.build_datatable()) >+ vm.getAgreementCount().then(() => vm.build_datatable()) > } > }) > }, >@@ -96,11 +96,11 @@ export default { > }, > }, > methods: { >- async getAgreements() { >+ async getAgreementCount() { > const client = APIClient.erm >- await client.agreements.getAll().then( >- agreements => { >- this.agreements = agreements >+ await client.agreements.count().then( >+ count => { >+ this.agreement_count = count > this.initialized = true > }, > error => {} >@@ -446,7 +446,7 @@ export default { > mounted() { > if (!this.building_table) { > this.building_table = true >- this.getAgreements().then(() => this.build_datatable()) >+ this.getAgreementCount().then(() => this.build_datatable()) > } > }, > components: { flatPickr, Toolbar }, >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue >index 348edf92df7..4496ccb0d18 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue >@@ -44,7 +44,7 @@ export default { > }, > data: function () { > return { >- package_count: [], >+ package_count: null, > initialized: false, > filters: { > package_name: this.$route.query.package_name || "", >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue >index 90ab757f389..e7fefaaa379 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue >@@ -42,7 +42,7 @@ export default { > }, > data: function () { > return { >- title_count: undefined, >+ title_count: null, > initialized: false, > filters: { > publication_title: this.$route.query.publication_title || "", >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue >index 84eb25bf441..df5e3af79c1 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue >@@ -1,8 +1,8 @@ > <template> > <div v-if="!initialized">{{ $__("Loading") }}</div> >- <div v-else-if="licenses" id="licenses_list"> >+ <div v-else-if="license_count" id="licenses_list"> > <Toolbar /> >- <div v-if="licenses.length" class="page-section"> >+ <div v-if="license_count > 0" class="page-section"> > <table :id="table_id"></table> > </div> > <div v-else-if="initialized" class="dialog message"> >@@ -38,21 +38,21 @@ export default { > }, > data: function () { > return { >- licenses: [], >+ license_count: null, > initialized: false, > } > }, > beforeRouteEnter(to, from, next) { > next(vm => { >- vm.getLicenses().then(() => vm.build_datatable()) >+ vm.getLicenseCount().then(() => vm.build_datatable()) > }) > }, > methods: { >- async getLicenses() { >+ async getLicenseCount() { > const client = APIClient.erm >- await client.licenses.getAll().then( >- licenses => { >- this.licenses = licenses >+ await client.licenses.count().then( >+ count => { >+ this.license_count = count > this.initialized = true > }, > error => {} >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js >index 8dbd9e5453a..5cf28a9d397 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js >@@ -35,7 +35,16 @@ export class ERMAPIClient extends HttpClient { > endpoint: "agreements/" + id, > body: agreement, > }), >- //count: () => this.count("agreements"), //TODO: Implement count method >+ count: (query = {}) => >+ this.count({ >+ endpoint: >+ "agreements?" + >+ new URLSearchParams({ >+ _page: 1, >+ _per_page: 1, >+ ...(query && { q: JSON.stringify(query) }), >+ }), >+ }), > }; > } > >@@ -70,6 +79,16 @@ export class ERMAPIClient extends HttpClient { > endpoint: "licenses/" + id, > body: license, > }), >+ count: (query = {}) => >+ this.count({ >+ endpoint: >+ "licenses?" + >+ new URLSearchParams({ >+ _page: 1, >+ _per_page: 1, >+ ...(query && { q: JSON.stringify(query) }), >+ }), >+ }), > }; > } > >-- >2.37.1 (Apple Git-137.1)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 32807
:
147111
|
147115
|
148654
|
148851
|
148894