File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 4
4
<span class =" title" >Similar: </span >
5
5
<ul class =" list" v-if =" story.similar && story.similar.length !== 0" >
6
6
<li v-for =" sim in story.similar" :key =" sim.id" >
7
- <span class =" box" v-bind:style =" { background: getColor(sim.score )}" v-bind:title =" sim.score " ></span >
8
- <router-link :to =" '/item/' + sim.id" >{{ sim.text }}</router-link >
7
+ <span class =" box" v-bind:style =" { background: getColor(sim.similarity_score )}" v-bind:title =" sim.similarity_score " ></span >
8
+ <router-link :to =" '/item/' + sim.id" >{{ sim.title }} | < b >{{ new Date(sim.time * 1000).getFullYear() }}</ b > | {{ sim.descendants }} comments </router-link >
9
9
</li >
10
10
</ul >
11
11
<div v-else class =" no-posts" >
Original file line number Diff line number Diff line change @@ -45,6 +45,20 @@ export default {
45
45
item . similar = similar [ idx ] ;
46
46
return item ;
47
47
} ) )
48
+ // Start fetching similar posts (potential performance issue...)
49
+ . then ( ( items ) => {
50
+ return fetchItems ( items . map ( i => i . similar ) . flat ( ) . map ( sim => sim . id ) )
51
+ . then ( similarItems => {
52
+ items . forEach ( item => {
53
+ item . similar = item . similar . map ( sim => {
54
+ const simItem = similarItems . find ( si => si . id === sim . id ) ;
55
+ return Object . assign ( { similarity_score : sim . score } , simItem ) ;
56
+ } ) ;
57
+ } ) ;
58
+ return items ;
59
+ } ) ;
60
+ } ) ;
61
+ // Stop fetching similar posts (potential performance issue...)
48
62
}
49
63
return items ;
50
64
} )
You can’t perform that action at this time.
0 commit comments