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 6 months ago

neopostmodern commented 6 months ago

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

neopostmodern commented 3 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")