func (r *queryResolver) SceneMarkerTags(ctx context.Context, scene_id string) ([]*models.SceneMarkerTag, error) {
	sceneID, err := strconv.Atoi(scene_id)
	if err != nil {
		return nil, err
	}

	var keys []int
	tags := make(map[int]*models.SceneMarkerTag)

	if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
		sceneMarkers, err := repo.SceneMarker().FindBySceneID(sceneID)
		if err != nil {
			return err
		}

		tqb := repo.Tag()
		for _, sceneMarker := range sceneMarkers {
			markerPrimaryTag, err := tqb.Find(sceneMarker.PrimaryTagID)
			if err != nil {
				return err
			}
			_, hasKey := tags[markerPrimaryTag.ID]
			if !hasKey {
				sceneMarkerTag := &models.SceneMarkerTag{Tag: markerPrimaryTag}
				tags[markerPrimaryTag.ID] = sceneMarkerTag
				keys = append(keys, markerPrimaryTag.ID)
			}
			tags[markerPrimaryTag.ID].SceneMarkers = append(tags[markerPrimaryTag.ID].SceneMarkers, sceneMarker)
		}

		return nil
	}); err != nil {
		return nil, err
	}

	// Sort so that primary tags that show up earlier in the video are first.
	sort.Slice(keys, func(i, j int) bool {
		a := tags[keys[i]]
		b := tags[keys[j]]
		return a.SceneMarkers[0].Seconds < b.SceneMarkers[0].Seconds
	})

	var result []*models.SceneMarkerTag
	for _, key := range keys {
		result = append(result, tags[key])
	}

	return result, nil
}
// Get scene marker tags which show up under the video.
Get scene marker tags which show up under the video.
// Get scene marker tags which show up under the video .
func (r *queryResolver) SceneMarkerTags(ctx context.Context, scene_id string) ([]*models.SceneMarkerTag, error) {
	sceneID, err := strconv.Atoi(scene_id)
	if err != nil {
		return nil, err
	}
	var keys []int
	tags := make(map[int]*models.SceneMarkerTag)
	if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
		sceneMarkers, err := repo.SceneMarker().FindBySceneID(sceneID)
		if err != nil {
			return err
		}
		tqb := repo.Tag()
		for _, sceneMarker := range sceneMarkers {
			markerPrimaryTag, err := tqb.Find(sceneMarker.PrimaryTagID)
			if err != nil {
				return err
			}
			_, hasKey := tags[markerPrimaryTag.ID]
			if !hasKey {
				sceneMarkerTag := &models.SceneMarkerTag{Tag: markerPrimaryTag}
				tags[markerPrimaryTag.ID] = sceneMarkerTag
				keys = append(keys, markerPrimaryTag.ID)
			}
			tags[markerPrimaryTag.ID].SceneMarkers = append(tags[markerPrimaryTag.ID].SceneMarkers, sceneMarker)
		}
		return nil
	}); err != nil {
		return nil, err
	}
	sort.Slice(keys, func(i, j int) bool {
		a := tags[keys[i]]
		b := tags[keys[j]]
		return a.SceneMarkers[0].Seconds < b.SceneMarkers[0].Seconds
	})
	var result []*models.SceneMarkerTag
	for _, key := range keys {
		result = append(result, tags[key])
	}
	return result, nil
}
func ( r * queryResolver ) SceneMarkerTags ( ctx context . Context , scene_id string ) ( [ ] * models . SceneMarkerTag , error ) { sceneID , err := strconv . Atoi ( scene_id ) if err != nil { return nil , err } var keys [ ] int tags := make ( map [ int ] * models . SceneMarkerTag ) if err := r . withReadTxn ( ctx , func ( repo models . ReaderRepository ) error { sceneMarkers , err := repo . SceneMarker ( ) . FindBySceneID ( sceneID ) if err != nil { return err } tqb := repo . Tag ( ) for _ , sceneMarker := range sceneMarkers { markerPrimaryTag , err := tqb . Find ( sceneMarker . PrimaryTagID ) if err != nil { return err } _ , hasKey := tags [ markerPrimaryTag . ID ] if ! hasKey { sceneMarkerTag := & models . SceneMarkerTag { Tag : markerPrimaryTag } tags [ markerPrimaryTag . ID ] = sceneMarkerTag keys = append ( keys , markerPrimaryTag . ID ) } tags [ markerPrimaryTag . ID ] . SceneMarkers = append ( tags [ markerPrimaryTag . ID ] . SceneMarkers , sceneMarker ) } return nil } ) ; err != nil { return nil , err } sort . Slice ( keys , func ( i , j int ) bool { a := tags [ keys [ i ] ] b := tags [ keys [ j ] ] return a . SceneMarkers [ 0 ] . Seconds < b . SceneMarkers [ 0 ] . Seconds } ) var result [ ] * models . SceneMarkerTag for _ , key := range keys { result = append ( result , tags [ key ] ) } return result , nil }
Get scene marker tags which show up under the video.
Get scene marker tags which show up under the video .
// Sort so that primary tags that show up earlier in the video are first.