🐛 Fix the ListPostV2 loading attachments again...
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
				
			|||||||
package queries
 | 
					package queries
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"git.solsynth.dev/hypernet/interactive/pkg/internal/database"
 | 
						"git.solsynth.dev/hypernet/interactive/pkg/internal/database"
 | 
				
			||||||
@@ -88,18 +89,16 @@ func ListPostV2(tx *gorm.DB, take int, offset int, order any, user *uint) ([]mod
 | 
				
			|||||||
	var usersId []uint
 | 
						var usersId []uint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Scan records that can be load egearly
 | 
						// Scan records that can be load egearly
 | 
				
			||||||
	for _, info := range posts {
 | 
						var bodies []models.PostStoryBody
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							raw, _ := json.Marshal(posts)
 | 
				
			||||||
 | 
							json.Unmarshal(raw, &bodies)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for idx, info := range posts {
 | 
				
			||||||
		if info.Publisher.AccountID != nil {
 | 
							if info.Publisher.AccountID != nil {
 | 
				
			||||||
			usersId = append(usersId, *info.Publisher.AccountID)
 | 
								usersId = append(usersId, *info.Publisher.AccountID)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if raw, ok := info.Body["attachments"].([]any); ok && len(raw) > 0 {
 | 
							attachmentsRid = append(attachmentsRid, bodies[idx].Attachments...)
 | 
				
			||||||
			attachmentsRid := make([]string, 0, len(raw))
 | 
					 | 
				
			||||||
			for _, v := range raw {
 | 
					 | 
				
			||||||
				if str, ok := v.(string); ok {
 | 
					 | 
				
			||||||
					attachmentsRid = append(attachmentsRid, str)
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	log.Debug().Int("attachments", len(attachmentsRid)).Int("users", len(usersId)).Msg("Scanned metadata to load for listing post...")
 | 
						log.Debug().Int("attachments", len(attachmentsRid)).Int("users", len(usersId)).Msg("Scanned metadata to load for listing post...")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user