Skip to content
Snippets Groups Projects
Verified Commit 0d72c67d authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Improved caching

parent 734f8f8c
Branches
No related tags found
No related merge requests found
...@@ -35,6 +35,23 @@ ...@@ -35,6 +35,23 @@
<img v-if="suggestion.avatar" :src="suggestion.avatar" alt="" class="circle"> <img v-if="suggestion.avatar" :src="suggestion.avatar" alt="" class="circle">
<a target="_blank" rel="noopener noreferrer" :href="suggestion.url" class="title">{{ suggestion.name }}</a> <a target="_blank" rel="noopener noreferrer" :href="suggestion.url" class="title">{{ suggestion.name }}</a>
<p>Score: {{ suggestion.weight }}</p> <p>Score: {{ suggestion.weight }}</p>
<a v-if="retributeProfiles[suggestion.fullId] === undefined" @click="lookup(suggestion.fullId)" class="secondary-content"><i class="material-icons">search</i></a>
<div v-else-if="retributeProfiles[suggestion.fullId]">
<h6>Donation platforms</h6>
<!-- {{ retributeProfiles[suggestion.fullId] }} -->
<template v-for="mean in retributeProfiles[suggestion.fullId].means">
<a
:href="mean.url"
:key="mean.id"
target="_blank"
rel="noopener noreferrer"
:class="['waves-effect', 'waves-light', 'btn-small']">
<span :title="mean.summary">{{ mean.provider }}</span>
</a>
</template>
</div>
<div v-else>No retribute information found for this account</div>
</li> </li>
</ul> </ul>
</div> </div>
...@@ -44,13 +61,16 @@ ...@@ -44,13 +61,16 @@
<script> <script>
import sources from '@/sources' import sources from '@/sources'
import orderBy from 'lodash/orderBy' import orderBy from 'lodash/orderBy'
import chunk from 'lodash/chunk'
import axios from 'axios'
export default { export default {
data () { data () {
return { return {
isLoading: false, isLoading: false,
results: {}, results: {},
aggregatedSuggestions: {} aggregatedSuggestions: this.$store.state.cache.aggregatedSuggestions || {},
retributeProfiles: this.$store.state.cache.retributeProfiles || {},
} }
}, },
computed: { computed: {
...@@ -103,15 +123,58 @@ export default { ...@@ -103,15 +123,58 @@ export default {
for(let i = 0; i < keys.length; i++){ for(let i = 0; i < keys.length; i++){
await this.results[keys[i]].promise await this.results[keys[i]].promise
} }
await this.lookupAll()
this.isLoading = false this.isLoading = false
},
async lookupAll () {
const toLookup = this.filteredSuggestions.filter((s) => {
return this.retributeProfiles[s.fullId] === undefined
})
const chunkSize = 5
const chunks = chunk(toLookup, chunkSize)
for (let i = 0; i < chunks.length; i++){
let chunk = chunks[i]
let ids = chunk.map((s) => {
return s.fullId
})
await this.lookups(ids)
}
},
async lookups(ids) {
const tasks = ids.map((i) => {
return this.lookup(i)
})
for (let i = 0; i < tasks.length; i++){
await tasks[i]
}
},
async lookup (id) {
const client = axios.create({timeout: 5000})
let url = `http://localhost:8000/api/v1/search/${id}`
try {
const response = await client.get(url)
this.$set(this.retributeProfiles, id, response.data)
} catch {
this.$set(this.retributeProfiles, id, null)
return
}
} }
}, },
watch: { watch: {
results: { results: {
handler (v) { handler (v) {
this.aggregatedSuggestions = this.aggregateSuggestions(v) this.aggregatedSuggestions = this.aggregateSuggestions(v)
this.$store.commit('setRecursiveState', {key: 'cache.aggregatedSuggestions', value: this.aggregatedSuggestions})
}, },
deep: true, deep: true,
},
retributeProfiles: {
handler (v) {
this.$store.commit('setRecursiveState', {key: 'cache.retributeProfiles', value: this.retributeProfiles})
},
deep: true
} }
} }
} }
......
...@@ -89,7 +89,7 @@ export default { ...@@ -89,7 +89,7 @@ export default {
baseURL: `https://${account.domain}`, baseURL: `https://${account.domain}`,
headers: {'Authorization': `Bearer ${token}`}, headers: {'Authorization': `Bearer ${token}`},
}) })
const maxFavorites = 500 const maxFavorites = 100
let url = '/api/v1/favourites' let url = '/api/v1/favourites'
let handledFavorites = 0 let handledFavorites = 0
results.progress = 0 results.progress = 0
......
...@@ -13,7 +13,8 @@ export const storeConfig = { ...@@ -13,7 +13,8 @@ export const storeConfig = {
state: { state: {
accounts: {}, accounts: {},
sources: {} sources: {},
cache: {}
}, },
mutations: { mutations: {
addAccount (state, payload) { addAccount (state, payload) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment