neopostmodern / structure

Structure is a knowledge management tool
https://structure.love
GNU Affero General Public License v3.0
17 stars 0 forks source link

Fetch tag frequency / sorted list from server #231

Open neopostmodern opened 11 months ago

neopostmodern commented 11 months ago

This would speed up the crazy slow cache-rebuilding on cold devices, plus it could easily be refreshed irregularly.

neopostmodern commented 7 months ago

Sample code

db.tags.aggregate([
  { 
    $lookup: { 
      from: "notes", 
      localField: "_id", 
      foreignField: "tags", 
      let: { tagId: "$_id" }, 
      pipeline: [ { $count: "count" } ], 
      as: "noteCount" 
   } 
  }, 
  { $unwind: "$noteCount" } 
])

keep performance in balance?

db.tags.aggregate([` { $lookup: { from: "notes", localField: "_id", foreignField: "tags", let: { tagId: "$_id" }, pipeline: [{ $count: "count" }], as: "noteCount" } }, { $unwind: '$noteCount' }, { $addFields: { noteCount: '$noteCount.count' } }] ).explain("executionStats")